有些人能解释这种现象?仅2 code线 [英] Some one can explain this behavior ? just 2 lines of code
问题描述
请解释一下这个片断:
的#include<&stdio.h中GT;诠释看跌期权(为const char *海峡){
的fputs(世界,你好\\ N!,标准输出);
}诠释主(){
的printf(再见\\ n);
}
输出:<!code>世界,你好返回13
这是编译器特定。你与 GCC 此行为。这里还有一些细节。
-
既然你
未定义行为>的#include&LT; stdio.h中&GT;
(实际上,因为你是在托管环境)的看跌
是C99的标准,并重新定义它是 -
GCC编译器有一些优化一些
的printf
来变换的的更快的看跌期权的顺序
。这是合法的,因为你已经包括&LT; stdio.h中&GT;
(和C99标准定义了的printf
应该做的在这种情况下,GCC会突破__ builtin_printf
作为一个中间步骤)
如果您编译 -ffreestanding
你不会观察到。
Kindly explain this snippet:
#include <stdio.h>
int puts(const char *str) {
fputs("Hello world!\n", stdout);
}
int main() {
printf("Goodbye\n");
}
Output : Hello world!
return 13
It is compiler specific. You get this behavior with GCC. Here are some details.
since you
#include <stdio.h>
(actually because you are in a hosted environment) theputs
is that of the C99 standard, and redefining it is undefined behaviorthe GCC compiler has some optimizations to transform some
printf
to a sequence of fasterputs
. This is legal, since you have included<stdio.h>
(and the C99 standard defines whatprintf
should do in that case; GCC goes thru__builtin_printf
as an intermediate step)
If you compile with -ffreestanding
you won't observe that.
Your question is very close to this one; so this answer is also relevant.
这篇关于有些人能解释这种现象?仅2 code线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!