Nested functions in C (was: Understanding Packages)

John Vetterli jvetterli-zC6tqtfhjqE at public.gmane.org
Tue Apr 20 15:21:27 UTC 2004


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.

JV
--
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