C89 C99 VS GCC编译器 [英] C89 vs c99 GCC compiler
本文介绍了C89 C99 VS GCC编译器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有,如果我编译使用C89 C99 VS下面的程序有区别吗?我得到的结果相同。难道真有这两者之间有区别吗?
的#include<&stdio.h中GT; 诠释的main()
{
//打印字符串到屏幕。
的printf(的Hello World \\ n);
}GCC -o的HelloWorld -std = C99 helloworld.c
VS
GCC -o的HelloWorld -std = C89 helloworld.c
解决方案
-
//
注释不C89的一部分,但都OK的C99, - 脱落的
的main()
不返回任何值等同于返回0;
在C99,但不因此,在C89。从 N1256 (PDF),5.1.2.2.3p1:
如果在
主
函数的返回类型是一种与INT
兼容,从最初的调用的返回主功能相当于调用退出
由主
函数作为参数返回的值的功能;到达}
终止的主
函数返回一个0值。
所以,你的code是未定义行为C89,和C99定义良好的行为。
块引用>
Is there a difference if I compile the following program using c89 vs c99? I get the same output. Is there really a difference between the two?
#include <stdio.h>
int main ()
{
// Print string to screen.
printf ("Hello World\n");
}
gcc -o helloworld -std=c99 helloworld.c
vs
gcc -o helloworld -std=c89 helloworld.c
解决方案
//
comments are not a part of C89 but are OK in C99,- falling off of
main()
without returning any value is equivalent toreturn 0;
in C99, but not so in C89. From N1256 (pdf), 5.1.2.2.3p1:If the return type of the
main
function is a type compatible withint
, a return from the initial call to the main function is equivalent to calling theexit
function with the value returned by themain
function as its argument; reaching the}
that terminates themain
function returns a value of 0.
这篇关于C89 C99 VS GCC编译器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文