use*_*514 9 c compiler-construction gcc c99 c89
如果我使用c89 vs c99编译以下程序有区别吗?我得到相同的输出.两者之间真的有区别吗?
#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
Run Code Online (Sandbox Code Playgroud)
从理论上讲,应该有一个区别.使用"//"来标记注释不是C89的一部分,因此如果它正确地强制执行C89规则,那将产生编译器错误(使用-ansi -pedantic,它可能会这样做,但我不记得了当然).
这给出了一般性的概念:如果程序编译为C89,它通常也会编译为C99,并给出完全相同的结果.C99主要购买了C89中不存在的一些新功能,因此您可以使用(例如)C89中不允许的可变长度数组.
您可能不得不要求迂腐规则执行以查看所有差异 - C99旨在标准化现有做法,并且一些现有做法是gcc扩展,其中一些默认启用.