现在,我之前已经读过这个小组,而且我知道我会为这么简单的问题得到这个简单的问题,但是:出了什么问题?为什么一个 编译器通过它而另一个不通过?Yet here I have a program which compiles without a peep under gcc4.2.1(with -ansi -Wall, no less), AND runs correctly, but which icc(10.1.015) won''t touch with a ten-foot-pole:=====begin sample program=====#include <stdio.h>int main(){ int sub1() { printf("1"); return(0); } int sub2(){ printf("2\n"); return(0); }/* start of main */ sub1(); sub2();}=======end sample program========I don''t see anything wrong with this. Nevertheless, icc aborts thecompilation with the fatal errortestit.c(6): error: expected a ";" { ^It doesn''t like the opening left-brace of "sub1".Now, I''ve read this group before, and I know I''m going to get reamedfor such a simple question, but: what''s wrong? And why does onecompiler pass it and the other doesn''t? 哪一个需要它?那么必须是一个不合格的。Which one takes it? Must be a non-conforming one then. 这是在2.5GHz核心2 duo上的openSuse 10.3,内存为3GB(尽管 这一切都不重要。 提前致谢,This is in openSuse 10.3 on a 2.5GHz core 2 duo with 3GB RAM (thoughnone of that matters).Thanks in advance, 再见,JojoBye, Jojo Joachim Schmitz写道:Joachim Schmitz wrote: Ronald Bruck写道:Ronald Bruck wrote: >叹息。自从我用C语言编程以来已经有一段时间了,但是我确定你可以拥有一个范围纯粹属于另一个功能的函数。你根本不能用C做这个。>Sigh. It''s been awhile since I''ve programmed in C, but I''m SURE thatyou can have a function whose scope is purely within anotherfunction. You simply can''t do this in C. >然而在这里我有一个程序可以在没有窥视的情况下进行编译。 gcc4 .2.1(带-ansi -Wall,不少),并且运行正常,但是icc(10.1.015)不会碰到10英尺杆: =====开始示例程序===== #include< stdio.h> int main() { int sub1() { printf(" 1"); 返回(0); } int sub2() { printf( 2 \ n;; 返回(0); } / *开始主* / sub1(); sub2(); } =======结束样本程序======== 我没有看到任何错误。尽管如此,icc在致命错误中止了编译。 testit.c(6):错误:预期a"" { ^ 它不喜欢sub1的开头左支撑。 现在,我之前读过这个小组,我知道我要走了为了这么简单的问题得到了解决,但是:出了什么问题?为什么一个编译器通过它而另一个没有?>Yet here I have a program which compiles without a peep undergcc4.2.1 (with -ansi -Wall, no less), AND runs correctly, but whichicc (10.1.015) won''t touch with a ten-foot-pole:=====begin sample program=====#include <stdio.h>int main(){ int sub1() { printf("1"); return(0); } int sub2(){ printf("2\n"); return(0); }/* start of main */ sub1(); sub2();}=======end sample program========I don''t see anything wrong with this. Nevertheless, icc aborts thecompilation with the fatal errortestit.c(6): error: expected a ";" { ^It doesn''t like the opening left-brace of "sub1".Now, I''ve read this group before, and I know I''m going to get reamedfor such a simple question, but: what''s wrong? And why does onecompiler pass it and the other doesn''t? 哪一个需要它?那么一定是不合格的。Which one takes it? Must be a non-conforming one then. 啊,我明白了,gcc。添加-pedantic以关闭非标准扩展Ah, I see, gcc. Add -pedantic to switch off that non-standard extension >这是在2.5GHz核心2 duo上的openSuse 10.3中3GB内存(虽然没有任何意义)。 提前致谢,>This is in openSuse 10.3 on a 2.5GHz core 2 duo with 3GB RAM (thoughnone of that matters).Thanks in advance, 再见,JojoBye, Jojo Ronald Bruck< br *** @ math.usc.eduwrote:Ronald Bruck <br***@math.usc.eduwrote: 叹息。自从我用C语言编程以来已经有一段时间了,但是我确定你可以拥有一个范围纯粹在另一个函数范围内的函数。Sigh. It''s been awhile since I''ve programmed in C, but I''m SURE thatyou can have a function whose scope is purely within another function. 仅作为编译器特定的扩展名。我想你正在混合那个 ,可以在另一个函数中声明(但没有定义)一个函数 。Only as a compiler specific extension. I guess you''re mixing thatup with the posibility to declare (but not define) a functionwithin another function. 然而在这里我有一个程序,在gcc4.2.1 (带-ansi -Wall,不低于),Yet here I have a program which compiles without a peep under gcc4.2.1(with -ansi -Wall, no less), $下无需窥视编译b $ b添加''-pedantic''到混音中它会告诉你 z6.c:6:警告:ISO C禁止嵌套函数 z6.c:11:警告:ISO C禁止嵌套函数Add ''-pedantic'' to the mix and it will tell youz6.c:6: warning: ISO C forbids nested functionsz6.c:11: warning: ISO C forbids nested functions AND正确运行,但是哪个icc ( 10.1.015)不会碰到10英尺杆:AND runs correctly, but which icc(10.1.015) won''t touch with a ten-foot-pole: 所以icc不支持这个扩展(至少不支持$ 默认为gcc)。So icc does not support this extension (at least not perdefault as gcc does). =====开始示例程序===== #include< stdio.h中>=====begin sample program=====#include <stdio.h> int main() { int sub1() { printf(" 1"); return(0); } int sub2() { printf(" 2 \ n"); return(0); } / *主要开始* / sub1(); sub2(); } =======结束样本程序========int main(){ int sub1() { printf("1"); return(0); } int sub2() { printf("2\n"); return(0); }/* start of main */ sub1(); sub2();}=======end sample program======== 我不喜欢看不出有什么不妥。尽管如此,icc使用致命错误I don''t see anything wrong with this. Nevertheless, icc aborts thecompilation with the fatal error testit.c(6)中止 编译:错误:预期a" ;;" { ^testit.c(6): error: expected a ";" { ^ 它不喜欢开幕式左支撑sub1。It doesn''t like the opening left-brace of "sub1". 如果你做的话,gcc也开始抱怨这条线 真的标准符合''-pedantic''。所有允许在 这个地方是'';''来结束函数的声明。 但是''{''会启动一个函数定义。 问候,Jens - \ Jens Thoms Toerring ___ [email protected] \ __________________________ http:// toerring.de 这篇关于私人职能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-28 05:40