Re: private functions
- From: jt@xxxxxxxxxxx (Jens Thoms Toerring)
- Date: 31 May 2008 15:33:19 GMT
Ronald Bruck <bruck@xxxxxxxxxxxx> wrote:
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.
Yet here I have a program which compiles without a peep under gcc4.2.1
(with -ansi -Wall, no less),
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 runs correctly, but which icc
(10.1.015) won't touch with a ten-foot-pole:
So icc does not support this extension (at least not per
default as gcc does).
=====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".
Also gcc starts complaining about that line if you make it
really standard compliant with '-pedantic'. All allowed at
this place is a ';' to end the declaration of the function.
But the '{' starts a function definition instead.
Regards, Jens
--
\ Jens Thoms Toerring ___ jt@xxxxxxxxxxx
\__________________________ http://toerring.de
.
- References:
- private functions
- From: Ronald Bruck
- private functions
- Prev by Date: Re: private functions
- Next by Date: struct padding ???
- Previous by thread: Re: private functions
- Next by thread: Re: private functions
- Index(es):
Relevant Pages
|