条件定义 [英] Conditional Define
问题描述
你好
有没有办法通过一个define来声明''FUNCT'',这样如果它的参数x,一个常数,就是
更大超过35,它返回56,如果没有,20。
我希望在编译时,而不是在运行时。
所以:
#define FUNCT(x)x> 35?56:20
不是我的问题的答案。
可能是类似的东西
#define FUNCT(x)#if(x> 35)56 #else 20 #endif
自' 'x''是常量,这可以由预处理器完成,所以我想有一个
的方法来做它。
也许吧这是一个愚蠢的问题,但这个问题有解决方案吗?
提前谢谢你,
Marco Lazzaroni
---------------
El sito de motumboe
http://www.motumboe.net
Marco Lazzaroni
Hello
Is there a way to declare ''FUNCT'' via a define so that if its parameter x, a constant, is
greater than 35, it returns 56, if not, 20.
I would like that at compile time, not at run time.
So:
#define FUNCT(x) x>35?56:20
is not the answer to my question.
Could be something like
#define FUNCT(x) #if (x>35) 56 #else 20 #endif
Since the ''x'' is a constant, this can be done by the preprocessor, so I suppose there''s a
way to do it.
Maybe it''s a stupid question but is there a solution to this issue?
Thank you in advance,
Marco Lazzaroni
---------------
El sito de motumboe
http://www.motumboe.net
Marco Lazzaroni
推荐答案
BQ< ca ********************* @ apochestolibero.it>潦草地写道:
BQ <ca*********************@apochestolibero.it> scribbled the following:
你好
有没有办法通过一个define来声明''FUNCT'',这样如果它的参数x,一个常数大于35,它返回56,如果没有,20。
我希望在编译时,而不是在运行时。
所以:
#define FUNCT(x)x> 35?56:20
不是我的问题的答案。
可能像
#define FUNCT (x)#if(x> 35)56 #else 20 #endif
由于''''是常量,这可以由预处理器完成,所以我想有一个
这样做的方式。
也许这是一个愚蠢的问题,但这个问题是否有解决方案?
提前谢谢,
Hello Is there a way to declare ''FUNCT'' via a define so that if its parameter x, a constant, is
greater than 35, it returns 56, if not, 20.
I would like that at compile time, not at run time. So: #define FUNCT(x) x>35?56:20 is not the answer to my question.
Could be something like #define FUNCT(x) #if (x>35) 56 #else 20 #endif Since the ''x'' is a constant, this can be done by the preprocessor, so I suppose there''s a
way to do it. Maybe it''s a stupid question but is there a solution to this issue?
Thank you in advance,
#if(x> 35)
#define FUNCT(x)56
#else
#define FUNCT(x)20
#endif
除非出现一些预处理器语法错误,否则你现在处于为什么
我没想到这个?贴在额头上。
-
/ - Joona Palaste(pa*****@cc.helsinki.fi)---- ---------芬兰-------- \
\-- http://www.helsinki.fi/~palaste ---------------------规则! -------- /
我们是女性。我们有双重标准可以实现。
- Ally McBeal
#if (x>35)
#define FUNCT(x) 56
#else
#define FUNCT(x) 20
#endif
Barring some preprocessor syntax errors, you''re now in for a "why
didn''t I think of that?" slap on the forehead.
--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"We''re women. We''ve got double standards to live up to."
- Ally McBeal
" BQ" < CA ********************* @ APOCHESTOlibero.it>在留言中写道
news:ph ******************* @ twister1.libero.it ...
"BQ" <ca*********************@APOCHESTOlibero.it> wrote in message
news:ph*******************@twister1.libero.it...
你好
有没有办法通过一个define来声明''FUNCT'',这样如果它的参数
x,一个常数大于35,它就会返回56,如果没有,则返回20。
我希望在编译时,而不是在运行时。
所以:
#define FUNCT(x)x> 35?56:20
不是我的问题的答案。
可能像
#define FUNCT(x)#if(x> 35)56 #else 20 #endif
这是错的。 #XXX是预处理器定义,所以不知道变量在执行过程中所取的值。
由于''''是一个常量,这可以由预处理器完成,所以我b $ b假设有办法做到这一点。
不,除非你使用#define作为'const''你的意思。
也许这是一个愚蠢的问题,但是有没有解决方案这个问题?
提前谢谢你,
Marco Lazzaroni
Hello
Is there a way to declare ''FUNCT'' via a define so that if its parameter x, a constant, is greater than 35, it returns 56, if not, 20.
I would like that at compile time, not at run time.
So:
#define FUNCT(x) x>35?56:20
is not the answer to my question.
Could be something like
#define FUNCT(x) #if (x>35) 56 #else 20 #endif
this is wrong. #XXX are pre-processor defines so do not know anything about
the values that variables take during execution.
Since the ''x'' is a constant, this can be done by the preprocessor, so I suppose there''s a way to do it.
No, unless you use a #define for the ''const'' you mean.
Maybe it''s a stupid question but is there a solution to this issue?
Thank you in advance,
Marco Lazzaroni
这不是一个愚蠢的问题,但是我的直接反应是,为什么?为什么没有
x> 35?56:20足够吗?
Allan
Its not s stupid question, but my immediate response is, why? why doesnt
x>35?56:20 suffice?
Allan
BQ< ca *** ******************@apochestolibero.it>潦草地写道:
BQ <ca*********************@apochestolibero.it> scribbled the following:
你好
有没有办法通过一个define来声明''FUNCT'',这样如果它的参数x,一个常数大于35,它返回56,如果没有,20。
我希望在编译时,而不是在运行时。
所以:
#define FUNCT(x)x> 35?56:20
不是我的问题的答案。
可能像
#define FUNCT (x)#if(x> 35)56 #else 20 #endif
由于''''是常量,这可以由预处理器完成,所以我想有一个
这样做的方式。
也许这是一个愚蠢的问题,但这个问题是否有解决方案?
提前谢谢,
Hello Is there a way to declare ''FUNCT'' via a define so that if its parameter x, a constant, is
greater than 35, it returns 56, if not, 20.
I would like that at compile time, not at run time. So: #define FUNCT(x) x>35?56:20 is not the answer to my question.
Could be something like #define FUNCT(x) #if (x>35) 56 #else 20 #endif Since the ''x'' is a constant, this can be done by the preprocessor, so I suppose there''s a
way to do it. Maybe it''s a stupid question but is there a solution to this issue?
Thank you in advance,
忘记我之前的回复(现在已取消)。它使用全局变量x
作为#if中的参数,而不是宏本身中的参数x。
我不觉得你是什么真的很想做就有可能。保持
介意宏的参数的实际值在运行时之前不知道
,因此在编译时#defining为56或20时间
需要千里眼。
-
/ - Joona Palaste(pa ***** @ cc。 helsinki.fi)-------------芬兰-------- \
\-- http://www.helsinki.fi/~palaste --------------- ------规则! -------- /
我希望我们认识的人会死,所以我们可以给他们留下鲜花。
- 一个6岁的孩子女孩,在墓地里看到鲜花
Forget my earlier reply (now cancelled). It used a global variable "x"
as the parameter in the #if, not the parameter x in the macro itself.
I don''t think what you really want to do is possible at all. Keep in
mind that the actual value of the argument for your macro isn''t known
until run-time, so #defining it to either 56 or 20 at compile time
would require clairvoyance.
--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"I wish someone we knew would die so we could leave them flowers."
- A 6-year-old girl, upon seeing flowers in a cemetery
这篇关于条件定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!