增量评估 [英] increment evaluation
问题描述
hii,
plz帮助详细了解这个prg wrk如何
#define CUBE(x)(x * x * x)
main()
{
int a,b = 3;
a = CUBE(b ++);
printf("%d%d",a,b);
}
hii,
plz help to knw how this prg wrk in detail
#define CUBE(x) (x*x*x)
main()
{
int a,b=3;
a=CUBE(b++);
printf("%d%d",a,b);
}
推荐答案
pr********@gmail.com 说:
hii,
plz帮助知道这个prg wrk的详细信息
hii,
plz help to knw how this prg wrk in detail
它没有。
It doesn''t.
#define CUBE(x)(x * x * x)
main()
{
int a,b = 3;
a = CUBE(b ++);
#define CUBE(x) (x*x*x)
main()
{
int a,b=3;
a=CUBE(b++);
参见常见问题解答: http://c-faq.com/cpp/safemacros.html
-
Richard Heathfield< http:/ /www.cpax.org.uk>
电子邮件:-http:// www。 + rjh @
谷歌用户:< http://www.cpax.org.uk/prg/writings/googly.php>
Usenet是一个奇怪的放置" - dmr 1999年7月29日
See the FAQ: http://c-faq.com/cpp/safemacros.html
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
10月12日上午12:03,pradeep ... @ gmail.com写道:
On Oct 12, 12:03 am, pradeep...@gmail.com wrote:
hii,
plz帮助详细了解这个prg wrk的方式
#define CUBE(x)(x * x * x)
main()
{
int a,b = 3;
a = CUBE(b ++);
printf("%d%d",a,b);
}
hii,
plz help to knw how this prg wrk in detail
#define CUBE(x) (x*x*x)
main()
{
int a,b=3;
a=CUBE(b++);
printf("%d%d",a,b);
}
这是一个未定义行为的示例(由于多种原因)。
你有一个varadic函数(printf),范围内没有原型。
你有一个函数宏给出一个参数使用超过
一次增加导致多次更新而没有干预
序列点。
可能你需要类似的东西这个:
#include< stdio.h>
静态长CUBE(const长x)
{
printf("%d *%d *%d",x,x,x);
return(x * x * x);
}
int main(无效)
{
长a;
int b = 3 ;
a = CUBE(b ++);
printf(" =%ld \ n",a);
a = CUBE(b);
printf(" =%ld \ n",a );
返回0;
}
That is an example of undefined behavior (for several reasons).
You have a varadic function (printf) with no protype in scope.
You have a function macro which is given an argument used more than
once which is incremented causing several updates with no intervening
sequence point.
Probably, you want something like this:
#include <stdio.h>
static long CUBE (const long x)
{
printf("%d * %d * %d ", x, x, x);
return (x * x * x);
}
int main (void)
{
long a;
int b = 3;
a = CUBE(b++);
printf (" = %ld\n", a);
a = CUBE(b);
printf (" = %ld\n", a);
return 0;
}
10月12日星期五2007 00:03:17 -0700,
pr ******** @ gmail.com < pr ******** @ gmail.comwrote:
On Fri, 12 Oct 2007 00:03:17 -0700,
pr********@gmail.com <pr********@gmail.comwrote:
hii,
plz帮助知道这是怎么回事prg wrk详细信息
hii,
plz help to knw how this prg wrk in detail
请将来尝试正确拼写。你在打字时节省的一点点努力,如果有的话,意味着你所有的读者都需要更加努力地解析你的信息。它看起来不是很酷
。看起来很傻。
Please, in the future, make an attempt to spell correctly. The little
bit of effort you save in typing, if any, means all your readers have to
work a little bit harder to parse your message. It doesn''t look cool
either. It looks silly.
#define CUBE(x)(x * x * x)
main()
{
int a,b = 3;
a = CUBE(b ++);
printf("%d%d", a,b);
}
#define CUBE(x) (x*x*x)
main()
{
int a,b=3;
a=CUBE(b++);
printf("%d%d",a,b);
}
由于多种原因,该程序调用未定义的行为。请点击c -faq.com上的C FAQ,然后阅读问题3.2,10.1,
11.35,15.21,然后阅读整篇文章。这真的值得花时间。
Martien
-
|
Martien Verbruggen |
|在一个没有围栏的世界里,谁需要盖茨?
|
This program invokes undefined behaviour, for several reasons. Please
see the C FAQ at c-faq.com, for example, and read questions 3.2, 10.1,
11.35, 15.21, and then read the whole thing. It''s really worth the time.
Martien
--
|
Martien Verbruggen |
| In a world without fences, who needs Gates?
|
这篇关于增量评估的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!