Nested functions in C (was: Understanding Packages)

Lennart Sorensen lsorense-1wCw9BSqJbv44Nm34jS7GywD8/FfD2ys at public.gmane.org
Tue Apr 20 19:44:06 UTC 2004


On Tue, Apr 20, 2004 at 11:21:27AM -0400, John Vetterli wrote:
> On Tue, 20 Apr 2004, Lennart Sorensen wrote:
> > On Sun, Apr 18, 2004 at 10:26:55PM -0400, Geoffrey Hunter wrote:
> > > C doesn't allow functions to be defined (nested) within other functions
> > So what does this look like to you:
> >
> > #include <stdio.h>
> > int main() {
> > 	int a,b;
> > 	void callMe(int x) {
> > 		printf("callMe called with %d\n",x);
> > 	}
> > 	a=4;
> > 	b=6;
> > 	callMe(9);
> > 	printf("a is %d\n",a);
> > 	callMe(10);
> > 	printf("b is %d\n",b);
> > 	callMe(1);
> > 	return 0;
> > }
> > No nesting in C?  Really?
> 
> Perhaps Geoffrey was referring to ANSI-C.  The GCC 3.3.3 manual has nested
> functions under Extensions; if you try to compile your program with the
> -ansi and -pedantic switches, it politely tells you "warning: ANSI C
> forbids nested functions".  I also tried to compile your program with MSVC
> 5.0, which only got confused and reported a syntax error.
> 
> http://gcc.gnu.org/onlinedocs/gcc-3.3.3/gcc/Nested-Functions.html
> 
> I know I'm nitpicking, but I tend to be of a "if it's not in the spec it
> doesn't count" mindset.

Well I am sure C++ does allow it (which is probably why gcc allows it in
C too, since it was easy).  It isn't something I ever see a use for
though.

Lennart Sorensen
--
The Toronto Linux Users Group.      Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml





More information about the Legacy mailing list