Nested Functions in C

Yes, you read the title right. No, I’m not crazy , OK maybe a bit (no pun intended). Maybe I’m sleep deprived, I honestly don’t remember when was the last time I had a good night’s sleep but it is true, C does support nested functions, All that you learnt about C was wrong (Gasp!!) Don’t trust me? Fine, go ahead and try the following code out.


         int main()

           void foo () {}return 0;


  GCC compiles it without a hitch. See, I told you! (again, no pun intended)I search around and figured out that ANSI ( C99 ) does not allow for nested functions. However, an addon for GCC provides support for it. I haven’t checked out its scoping rules or made any progress along that path. Do let me know if you find this out.



Published by


Hi!, My name is Gokula Krishnan, you can (and I prefer) call me gokul. I'm a third year Computer Science major from BITS Pilani. I'm interested in Technology, Theoretical Computer Science and Discrete Mathematics. A FOSS enthusiast, I'm one of the founders of the BITS Firefox community. I'm currently working on Big Data Analytics, Machine learning and UNIX shell programming. My not-so-geeky hobbies include playing volleyball and football and origami

2 thoughts on “Nested Functions in C”

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s