此帖出自编程基础论坛
最新回复
#define st(x) do { x } while (__LINE__ == -1)
讲解:
__LINE__ 是个宏,它代表当前代码在源文件的行号,它是大于0的,所以__LINE__ == -1 等同于0,化简为:
#define st(x) do { x } while (0)
Example:
#define a(x) if(x) { printf("%s\n", "OK"); }
int i = 1;
if(0)
a(i);
else
printf("%s\n", "KO");
Will expand to something equivalent to:
if(0)
{
if(x)
{
printf("%s\n", "OK");
}
else printf("%s\n", "KO");
}
However if you define a(x) as:
#define a(x) st(if(x) { printf("%s\n", "OK"); })
it will work, expanding to:
if(0)
{
do
{
if(x)
{
printf("%s\n", "OK");
}
}
while(0);
}
else printf("%s\n", "KO");
详情
回复
发表于 2015-12-1 15:35
赞赏 | ||
|
||
此帖出自编程基础论坛
| ||
|
||
此帖出自编程基础论坛
赞赏 | ||
|
||
此帖出自编程基础论坛
赞赏 | ||
|
||
此帖出自编程基础论坛
| ||
|
||
此帖出自编程基础论坛
| ||
|
||
| |
|
|
| |
个人签名专注智能产品的研究与开发,专注于电子电路的生产与制造……QQ:2912615383,电子爱好者群: void
|
|
| |
|
|
| |
|
|
| |
|
|
| |
|
|
此帖出自编程基础论坛
| ||
|
||
浏览过的版块 |
曾经的版主且威望大于2000,或对EEWORLD论坛有突出贡献的坛友
EEWorld Datasheet 技术支持