Simulater /生成switch语句范围在C [英] Simulater/Generated switch statement range in c

查看:192
本文介绍了Simulater /生成switch语句范围在C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有支持范围的情况下在C(99?)或客观C开关语句是一个黑客?
我知道这是不支持这样写的:

Is there a hack to support range case in a c(99?) or objective C switch statement ? I know this is not supported to write something like this:

switch(x)
   case 1:
   case 2..10:
   case 11:

不过,我想应该有产生code用#define宏的方式。当然
我可以定义一个宏案件的名单,但我希望有更优雅的方式一样
CASERANGE(X,X + 10),这将产生

But I was thinking there should be a way to generate code with a #define macro. Of course I can define a macro with the list of cases but I was hoping for a more elegant way like CASERANGE(x,x+10) which would generate:

case x
case x+1
case x+2

是它甚至可能吗?

is it even possible ?

推荐答案

GCC拥有的扩展的C语言,允许类似于您的第一个例子中的东西,但除此之外,如果有这样做的一个便携式/ ANSI方式,它会被完事了。我不相信有一个。

GCC has an extension to the C language that allows something similar to your first example, but other than that, if there was a portable/ANSI way of doing it, it would have been done by now. I don't believe there is one.

这篇关于Simulater /生成switch语句范围在C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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