Re: private functions



Joachim Schmitz wrote:
Ronald Bruck 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. You simply can't do this in C.

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.
Ah, I see, gcc. Add -pedantic to switch off that non-standard extension

This is in openSuse 10.3 on a 2.5GHz core 2 duo with 3GB RAM (though
none of that matters).

Thanks in advance,

Bye, Jojo


.



Relevant Pages

  • 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)
  • Re: What is a type?
    ... >> compilation time. ... The type int is perfectly supported by ... You probably won't find the term "int" in a CPU reference manual. ... I meant that a function pointer could be implemented as an index into ...
    (comp.lang.c)
  • Re: Vertical Text with TextOut()
    ... actually put some conditional compilation around it; then when I moved it to my laptop I'd ... I've got to update the Font Explorer (that was also on my ToDo List for the San Diego ... afx_msg void OnPaint; ... afx_msg void OnSize(UINT nType, int cx, int cy); ...
    (microsoft.public.vc.mfc)
  • Re: C Compilers
    ... int main ... Chars read: 190,Total compilation time = 0.003 sec. ... Ok, not a conformance issue. ...
    (comp.lang.c)
  • Re: simple question
    ... declaring the prototype of a function earlier and defining it later ... Doesn't having a function prototype also add type checking on the ... compilation unit and can ... void foo(int i, int n); ...
    (comp.lang.c)