问题描述
有人可以列出各种宏操作符及其含义。来自功能宏的
:
#define max(a,b)((a)>(b)?(a):( b ))
什么是? amd":"在这个陈述中是什么意思?
Zach
Can someone list the various macro operators and what they mean. Came
across a function macro:
#define max(a, b) ((a)>(b)?(a):(b))
What does "?" amd ":" mean in this statement?
Zach
推荐答案
K& R2,p51,58
H& S3, p198
相关,来自C-FAQ:
3.16:我有一个复杂的表达式,我必须分配给
$ b之一$ b两个变量,取决于条件。我可以使用像
这样的代码吗?
((条件)?a:b)= complex_expression;
答:不可以。?运算符与大多数运算符一样,产生一个值,并且你不能将值分配给b $ b。 (换句话说,?:不会产生
和左值。)如果你真的想,你可以试试像
*( (条件)?& a:& b)= complex_expression;
虽然这不是很漂亮。
参考文献:ISO秒。 6.3.15; H& S Sec。 7.1 pp.179-180。
http://www.phim.unibe.ch/comp_doc/c_...nditional.html
K&R2, p51,58
H&S3, p198
Related, from the C-FAQ:
3.16:I have a complicated expression which I have to assign to one of
two variables, depending on a condition. Can I use code like
this?
((condition) ? a : b) = complicated_expression;
A:No. The ?: operator, like most operators, yields a value, and
you can''t assign to a value. (In other words, ?: does not yield
an "lvalue".) If you really want to, you can try something like
*((condition) ? &a : &b) = complicated_expression;
although this is admittedly not as pretty.
References: ISO Sec. 6.3.15; H&S Sec. 7.1 pp. 179-180.
对于它造成的所有细微副作用也非常危险。
foo = max(a ++,b ++) ;
[snip]
And also quite dangerous for all of the subtle side effects it causes.
foo = max(a++,b++);
[snip]
这篇关于宏观运营商?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!