私人职能 [英] private functions
问题描述
叹息。这已经有一段时间了,因为我已经用C语言编程了,但是我确定你可以拥有一个范围纯粹属于另一个函数的函数。
然而在这里我有一个程序,在gcc4.2.1
下没有窥视编译(带-ansi -Wall,不少),并且运行正常,但是哪个icc
(10.1.015)不会碰到一个10英尺的杆子:
=====开始样本计划=====
#include< stdio.h>
int main()
{
int sub1()
{
printf(" 1");
return(0);
}
int sub2()
{
printf(" 2 \ n");
return(0);
}
/ *主要开始* /
sub1();
sub2();
}
=======结束示例程序========
我没有看到任何问题这个。尽管如此,icc中止了
汇编与致命错误
testit.c(6):错误:预期a" ;;"
{
^
它不喜欢左下角的sub1。
>
现在,我之前已经读过这个小组,而且我知道我会为这么简单的问题得到这个简单的问题,但是:出了什么问题?为什么一个
编译器通过它而另一个没有?
这是在2.5GHz核心2 duo和3GB RAM的openSuse 10.3中(虽然
但这一切都不重要。)
提前致谢,
-
Ron Bruck
Sigh. It''s been awhile since I''ve programmed in C, but I''m SURE that
you can have a function whose scope is purely within another function.
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 the
compilation with the fatal error
testit.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 reamed
for such a simple question, but: what''s wrong? And why does one
compiler pass it and the other doesn''t?
This is in openSuse 10.3 on a 2.5GHz core 2 duo with 3GB RAM (though
none of that matters).
Thanks in advance,
--
Ron Bruck
推荐答案
Ronald Bruck写道:
Ronald Bruck wrote:
叹息。自从我用C语言编程以来已经有一段时间了,但是我确定你可以拥有一个范围纯粹在另一个函数范围内的函数。
Sigh. It''s been awhile since I''ve programmed in C, but I''m SURE that
you can have a function whose scope is purely within another function.
你根本无法在C中这样做。
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");
return(0);
}
int sub2()
{
printf(" 2 \ n");
return(0);
}
/ *主要开始* /
sub1();
sub2();
}
=======结束样本程序========
我没有看到任何错误。尽管如此,icc中止了
汇编与致命错误
testit.c(6):错误:预期a" ;;"
{
^
它不喜欢左下角的sub1。
>
现在,我之前已经读过这个小组,而且我知道我会为这么简单的问题得到这个简单的问题,但是:出了什么问题?为什么一个
编译器通过它而另一个不通过?
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 the
compilation with the fatal error
testit.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 reamed
for such a simple question, but: what''s wrong? And why does one
compiler 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 (though
none of that matters).
Thanks in advance,
再见,Jojo
Bye, 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 that
you can have a function whose scope is purely within another
function. 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 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 the
compilation with the fatal error
testit.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 reamed
for such a simple question, but: what''s wrong? And why does one
compiler 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 (though
none of that matters).
Thanks in advance,
再见,Jojo
Bye, 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 that
you can have a function whose scope is purely within another function.
仅作为编译器特定的扩展名。我想你正在混合那个
,可以在另一个函数中声明(但没有定义)一个函数
。
Only as a compiler specific extension. I guess you''re mixing that
up with the posibility to declare (but not define) a function
within 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 you
z6.c:6: warning: ISO C forbids nested functions
z6.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 per
default 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 the
compilation 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 ___ jt@toerring.de
\ __________________________ http:// toerring.de
这篇关于私人职能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!