意外的答案,编译错误? [英] Unexpected answer, compiler bug?
问题描述
我运行下面的程序。它应该打印2但实际打印
out 1.发生了什么?我应该报告编译器的错误吗?
谢谢。
void main()
{
int a = 1;
a = a ++;
printf("%d",a);
}
Port Pirie写道:
我运行下面的程序。它应该打印2但实际打印
out 1.发生了什么?我应该报告编译器的错误吗?
谢谢。
void main()
{
int a = 1;
a = a ++;
printf("%d",a);
}
您已调用未定义的行为三次。首先,无效的主要原因不是适当的原型。正确的形式是int main(void)或int main(int,
char **)。其次,您访问一个对象,在序列点内修改它的值两次
。第三,你正在调用一个可变函数
,没有原型范围。
请通过以下链接阅读常见问题:
< http://www.c-faq.com/>
< http://www.clc-wiki.net/>
在文章< fk ********** @ aioe.orgPort Pirie< no *** @ nospam.invalidwrote:
>我运行下面的程序。它应该打印2但实际上它打印出来1.发生了什么?我应该报告编译器的错误吗?
void main()
int a = 1;
a = a ++;
printf("%d",a);
}
您问过一个常见问题3.1的变体,3.2和3.3。
请参阅< http://c-faq.com/expr/index.html>。另见问题11.12a至
11.15 at< http://c-faq.com/ansi/index.html> ;.
-
In-Real-Life:风河系统Chris Torek
美国犹他州盐湖城(40°39.22''N,111°50.29''W)+1 801 277 2603
电子邮件:忘了它 http:// web .torek.net / torek / index.html
由于垃圾邮件发送者,阅读电子邮件就像在垃圾中搜索食物一样。
< BLOCKQUOTE>"桑托什" < sa ********* @ gmail.comschrieb im Newsbeitrag
news:fk ********** @ registered.motzarella.org ...
Port Pirie写道:
>
我运行程序下面。它应该打印2但实际上它打印出来1.发生了什么?我应该报告编译器的错误吗?
谢谢。
void main()
{
int a = 1;
a = a ++;
printf("%d",a);
}
您已调用未定义的行为三次。
实际四次
首先无效主要不是
正确原型。正确的形式是int main(void)或int main(int,
char **)。其次,您访问一个对象,在序列点内修改它的值两次
。第三,你正在调用一个可变函数
而没有原型范围。
和第四个你不会以一个\\\
再见结束你的输出,Jojo
Hi,
I ran the program below. It should print out 2 but actually it prints
out 1. What''s going on? Should I report a bug against the compiler?
Thanks.
void main()
{
int a=1;
a=a++;
printf("%d", a);
}
Port Pirie wrote:
Hi,
I ran the program below. It should print out 2 but actually it prints
out 1. What''s going on? Should I report a bug against the compiler?
Thanks.
void main()
{
int a=1;
a=a++;
printf("%d", a);
}You have invoked undefined behaviour thrice. Firstly void main is not
the proper prototype. Proper forms are int main(void) or int main(int,
char**). Secondly you access an object to modify it''s value twice
within a sequence point. Thirdly you are calling a variadic function
with no prototype in scope.
Please read the FAQ at the following link:
<http://www.c-faq.com/>
<http://www.clc-wiki.net/>
In article <fk**********@aioe.orgPort Pirie <no***@nospam.invalidwrote:>I ran the program below. It should print out 2 but actually it prints
out 1. What''s going on? Should I report a bug against the compiler?
void main()
{
int a=1;
a=a++;
printf("%d", a);
}You have asked a variant of Frequently Asked Questions 3.1, 3.2, and 3.3.
See <http://c-faq.com/expr/index.html>. See also questions 11.12a through
11.15 at <http://c-faq.com/ansi/index.html>.
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22''N, 111°50.29''W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
"santosh" <sa*********@gmail.comschrieb im Newsbeitrag
news:fk**********@registered.motzarella.org...Port Pirie wrote:
>Hi,
I ran the program below. It should print out 2 but actually it prints
out 1. What''s going on? Should I report a bug against the compiler?
Thanks.
void main()
{
int a=1;
a=a++;
printf("%d", a);
}
You have invoked undefined behaviour thrice.Four times actually
Firstly void main is not
the proper prototype. Proper forms are int main(void) or int main(int,
char**). Secondly you access an object to modify it''s value twice
within a sequence point. Thirdly you are calling a variadic function
with no prototype in scope.and fourth you don''t end your output with a \n
bye, Jojo
这篇关于意外的答案,编译错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!