Re: private functions



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
.



Relevant Pages

  • Re: ptrs validity
    ... When you type "gcc", what compiler do you get? ... It depends on the extension on the filename. ... that try and catch are not part of the standard C language. ...
    (comp.lang.c)
  • Re: undefined reference to `__gxx_personality_sj0
    ... > When I change the extension to lowercase ... gcc try to determine the ... .C is not considered to be a file extension for C source ... Read the compiler documentation. ...
    (comp.lang.c)
  • Re: WHILE
    ... it is possible to implement this extension in pure ANS Forth. ... BTW: Same author: bigForth didn't have interactive DOES>, ... Furthermore, compare that to the situation of GCC: ... compiler, and the argument you get is "this is not portable code, anyway". ...
    (comp.lang.forth)
  • Re: question about cast
    ... >Your compiler uses some extension to the C language. ... the GNU C Compiler (gcc), ... For more details on gcc's weird sort-of-like-C language GNUC (which ...
    (comp.lang.c)
  • Re: Whats the story with the "end of XP"?
    ... Support gives them access to the larger body ... The same compiler suite may be "best" in both ... In the case of ByteCraft compilers, you are truly expert in your field, you work closely and rapidly with customers if there are any issues, and you have top class testing and quality control. ... understanding the inner workings of a relatively simple compiler like GCC ...
    (comp.arch.embedded)