private functions



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
.



Relevant Pages

  • Re: Dialog box and Custom control
    ... compiles fine in VC6 but fails in VS2008, because the scope of the 'i' variable is inside for loop in VS2008. ... int i; // scope of 'i' outside for loop ...
    (microsoft.public.vc.mfc)
  • Re: private functions
    ... you can have a function whose scope is purely within another function. ... int main ... Nevertheless, icc aborts the ... compilation with the fatal error ...
    (comp.lang.c)
  • Problem in compiling a C code with MSVC++6.00
    ... When I save the file as a cpp file, it compiles and runs ... int p1; ... void checkfile; ... printf("cannot allocate memory for elements!"); ...
    (comp.lang.c)
  • Re: Errors in compilation of simple programme
    ... using namespace std; ... cin>> i; ... it compiles without a problem on Visual C++ ... int main ...
    (microsoft.public.vc.language)
  • Re: Prime Numbers
    ... /*This code finally compiles as a 'c' code ... One more question....if i don't free up the memory allocated at the end ... it would appear that we are best served by an array ... prime numbers can be represented by an unsigned long int. ...
    (comp.lang.c)