LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 02-05-2006, 12:50 AM   #1
arunka
Member
 
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");
}
main()
{
int fun1()
{
fun();
}
}

Under gcc it compiled successfully and outwas
Inside fun

How this is possible??

thanks in advance

Arun
 
Old 02-05-2006, 01:08 AM   #2
paulsm4
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:
Code:
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
 
  


Reply


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 09:14 AM
accessing variables inside a function bahadur Programming 1 03-27-2005 04:41 AM
problem on dynamic function call inside a class! antony_csf Programming 0 06-29-2004 10:15 PM
A main can be changed by a function local without passing anything to the function? ananthbv Programming 10 05-04-2004 01:31 PM
Perl exec function in linux (and system-function) nazula Programming 1 04-19-2004 12:21 PM


All times are GMT -5. The time now is 08:35 PM.

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