View the Most Wanted LQ Wiki articles.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 02-05-2006, 01:50 AM   #1
Registered: Mar 2005
Posts: 60

Rep: Reputation: 15
function defn inside a function in C...!!!

hi all
i wrote a small program like ths

#include <stdio.h>
int fun()
printf("Inside fun");
int fun1()

Under gcc it compiled successfully and outwas
Inside fun

How this is possible??

thanks in advance

Old 02-05-2006, 02:08 AM   #2
LQ Guru
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
It works with "-pedantic"...

Hi -

I'm surprised it accepted it, too. Maybe there's a legitimate reason, maybe it's just a bug. I don't know.

Nevertheless, it's generally a good idea to make a habit of using the "-pedantic" and "-Wall" compiler switches. Your test is a good example of why:
gcc -pedantic -Wall -g -o x x.c
x.c: In function `fun':
x.c:5: warning: control reaches end of non-void function
x.c: In function `main':
x.c:11: warning: ISO C forbids nested functions
x.c: In function `fun1':
x.c:13: warning: control reaches end of non-void function
x.c: In function `main':
x.c:14: warning: control reaches end of non-void function


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Defining a non-inline function inside class definition (tm) Programming 6 05-11-2005 10:14 AM
accessing variables inside a function bahadur Programming 1 03-27-2005 05:41 AM
problem on dynamic function call inside a class! antony_csf Programming 0 06-29-2004 11:15 PM
A main can be changed by a function local without passing anything to the function? ananthbv Programming 10 05-04-2004 02:31 PM
Perl exec function in linux (and system-function) nazula Programming 1 04-19-2004 01:21 PM

All times are GMT -5. The time now is 08:58 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration