宏观运营商? [英] macro operators?

查看:85
本文介绍了宏观运营商?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以列出各种宏操作符及其含义。来自功能宏的



#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

推荐答案

2月20日,7:14下午,扎克 < net ... @ gmail.comwrote:
On Feb 20, 7:14 pm, "Zach" <net...@gmail.comwrote:

有人可以列出各种宏运算符及其含义。来自功能宏的



#define max(a,b)((a)>(b)?(a):( b ))


什么是? amd":"这句话意味着什么?
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?

http: //www.phim.unibe.ch/comp_doc/c_...nditional.html

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.


使用?并且:意味着它是一个条件函数。 in ur stmt" #define

max(a,b)((a)>(b)?(a):( b))

" a和b之间的较大数字将从函数max返回。使用

宏,意味着在编译时分配max的值。这使得b / b
对程序执行有效。

Zach写道:
use of ? and : means it''s a conditional function. in ur stmt "#define
max(a, b) ((a)>(b)?(a):(b))
" larger number between a and b will return from function max. use of
macro, means the value of max is assigned at compile time. this makes
efficient to the program execution.
Zach wrote:

有人可以列出各种宏运算符他们的意思是什么。来自功能宏的



#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


2月20日,下午7:49,madhawi < madhaw ... @ gmail.comwrote:
On Feb 20, 7:49 pm, "madhawi" <madhaw...@gmail.comwrote:

使用?并且:意味着它是一个条件函数。 in ur stmt" #define

max(a,b)((a)>(b)?(a):( b))

" a和b之间的较大数字将从函数max返回。使用

宏,意味着在编译时分配max的值。这使得

对程序执行有效。
use of ? and : means it''s a conditional function. in ur stmt "#define
max(a, b) ((a)>(b)?(a):(b))
" larger number between a and b will return from function max. use of
macro, means the value of max is assigned at compile time. this makes
efficient to the program execution.



对于它造成的所有细微副作用也非常危险。


foo = max(a ++,b ++) ;


[snip]

And also quite dangerous for all of the subtle side effects it causes.

foo = max(a++,b++);

[snip]


这篇关于宏观运营商?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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