如何使用省略号在C的case语句? [英] How to use ellipsis in c's case statement?

查看:220
本文介绍了如何使用省略号在C的case语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CASE expr_no_commas ELLIPSIS expr_no_commas ':'

我在C的语法规则,看到了这样的规则,但是当我尝试重现它:

I saw such a rule in c's syntax rule,but when I try to reproduce it:

int test(float i)
{
switch(i)
{
  case 1.3:
    printf("hi");
}
}

它失败...

推荐答案

确定,这涉及到对我而言有点猜测,但它会出现你在谈论一个 GCC 扩展到C,允许一个指定开关案件范围。

OK, this involves a bit of guesswork on my part, but it would appear that you're talking about a gcc extension to C that allows one to specify ranges in switch cases.

对我来说,编译如下:

int test(int i)
{
  switch(i)
  {
  case 1 ... 3:
    printf("hi");
  }
}

请注意在 ... 还要注意你不能在浮动切换。

Note the ... and also note that you can't switch on a float.

这篇关于如何使用省略号在C的case语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆