printf执行问题 [英] printf execution problem

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

问题描述

printf输出是否依赖于编译器或操作系统?我有一个项目



int main()

{

int i = 5;

printf("%d%d%d",i ++,i ++,i ++);

返回0;

}

在DOS(TC)上输出此程序7 6 5

Windows上此程序的输出(VC ++)5 5 5

Linux(GCC)上此程序的输出7 6 5

因此这些输出结果表明该程序的行为未定义。

是吗?

但是任何人都可以有任何其他答案在操作系统方面的这种行为

或编译器???

感谢您的帮助。

Does printf output depends on compilers or operating systems? I have
one program
int main()
{
int i=5;
printf("%d %d %d",i++,i++,i++);
return 0;
}
Output of this program on DOS (TC) 7 6 5
Output of this program on Windows (VC++) 5 5 5
Output of this program on Linux (GCC) 7 6 5
so these outputs conlude that behaviour of this program is undefined.
is that right?
but can anybody have any other answer to this behaviour in terms of OS
or Compiler???
Thanks for help.

推荐答案

ra*******@gmail.com 写道:
printf输出是否依赖于编译器或操作系统?我有一个程序
int main()
{i / 5;
printf("%d%d%d",i ++,i ++, i ++);
返回0;
}
在DOS(TC)上输出此程序7 6 5
在Windows上输出此程序(VC ++)5 5 5 在Linux(GCC)上输出这个程序7 6 5
所以这些输出可以说明这个程序的行为是不确定的。
是吗?
但任何人都可以对此有任何其他答案操作系统的行为
或编译器???
感谢您的帮助。
Does printf output depends on compilers or operating systems? I have
one program
int main()
{
int i=5;
printf("%d %d %d",i++,i++,i++);
return 0;
}
Output of this program on DOS (TC) 7 6 5
Output of this program on Windows (VC++) 5 5 5
Output of this program on Linux (GCC) 7 6 5
so these outputs conlude that behaviour of this program is undefined.
is that right?
but can anybody have any other answer to this behaviour in terms of OS
or Compiler???
Thanks for help.




这取决于编译器和选择的优化级别

用于该编译器。


函数的参数以适合

编译器的顺序进行评估。 Std C90,6.5,第1段渲染未定义你给我们的样品。



It depends on the compiler and on the level of optimization selected
for that complier.

Parameters of a function are evaluated in whichever order suits the
compiler. Std C90, 6.5, paragraph 1 renders undefined the sample you
have given us.




rahul8 ... @ gmail.com写道:

rahul8...@gmail.com wrote:
printf输出是否依赖于编译器或操作系统?我有一个程序
int main()
{i / 5;
printf("%d%d%d",i ++,i ++, i ++);
返回0;
}
在DOS(TC)上输出此程序7 6 5
在Windows上输出此程序(VC ++)5 5 5 在Linux(GCC)上输出这个程序7 6 5
所以这些输出可以说明这个程序的行为是不确定的。
是吗?
但任何人都可以对此有任何其他答案操作系统的行为
或编译器???
感谢您的帮助。
Does printf output depends on compilers or operating systems? I have
one program
int main()
{
int i=5;
printf("%d %d %d",i++,i++,i++);
return 0;
}
Output of this program on DOS (TC) 7 6 5
Output of this program on Windows (VC++) 5 5 5
Output of this program on Linux (GCC) 7 6 5
so these outputs conlude that behaviour of this program is undefined.
is that right?
but can anybody have any other answer to this behaviour in terms of OS
or Compiler???
Thanks for help.




在发布之前学习阅读小组和常见问题解答,这是问了所有

的时间。
http://www.eskimo.com/~scs/C-faq/q3.2.html


我希望Google群组支持killfiles 。


-David



Learn to read the group and FAQ before posting, this is asked all the
time.
http://www.eskimo.com/~scs/C-faq/q3.2.html

I wish google groups supported killfiles.

-David




David Resnick写道:

David Resnick wrote:
rahul8 ... @ gmail.com写道:
rahul8...@gmail.com wrote:
printf输出是否依赖于编译器或操作系统?我有一个程序
int main()
{i / 5;
printf("%d%d%d",i ++,i ++, i ++);
返回0;
}
在DOS(TC)上输出此程序7 6 5
在Windows上输出此程序(VC ++)5 5 5 在Linux(GCC)上输出这个程序7 6 5
所以这些输出可以说明这个程序的行为是不确定的。
是吗?
但任何人都可以对此有任何其他答案操作系统的行为
或编译器???
感谢您的帮助。
在发布之前学习阅读小组和常见问题解答,这是所有时间的问题。
http://www.eskimo.com/ ~scs / C-faq / q3.2.html
Does printf output depends on compilers or operating systems? I have
one program
int main()
{
int i=5;
printf("%d %d %d",i++,i++,i++);
return 0;
}
Output of this program on DOS (TC) 7 6 5
Output of this program on Windows (VC++) 5 5 5
Output of this program on Linux (GCC) 7 6 5
so these outputs conlude that behaviour of this program is undefined.
is that right?
but can anybody have any other answer to this behaviour in terms of OS
or Compiler???
Thanks for help.
Learn to read the group and FAQ before posting, this is asked all the
time.
http://www.eskimo.com/~scs/C-faq/q3.2.html



我先阅读上面的链接,然后决定提问。

链接表示这样的程序行为是未定义的,取决于

编译器。但我认为这是对操作系统的这种

行为的任何隐藏关系。如今没有人使用DOS,但每个人都说要使用GCC

,但大多数人也使用VC ++。所以它不会造成一个

编译器的战争(使用哪个?)我希望谷歌团体支持killfiles。

-David


I have first read above link and then decided to ask question. The
link said that such programs behaviour is undefined and depends on
compiler. But i thought that is there any hidden relationship of this
behaviour to OS. Nowadays no one uses DOS but everybody says to use GCC
but most people also uses VC++. so doesn''t it create a war of
compilers(which to use?) I wish google groups supported killfiles.

-David






这篇关于printf执行问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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