C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 25th, 2012, 03:45 PM
littlerunaway littlerunaway is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 2 littlerunaway User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 51 sec
Reputation Power: 0
Nested functions

can someone please explain what are nested functions exactly?
I'm writing a program with some functions. some of those functions are used within other functions.
I've done it before with another program that works fine but now I get this error:
"ISO C forbids nested functions"
can it be because I use a certain function within itself? I tried it with a little simple program just to check if it's possible and it worked fine. so I don't get what the problem is.

Reply With Quote
  #2  
Old December 25th, 2012, 03:56 PM
salem's Avatar
salem salem is offline
Contributed User
Click here for more information
 
Join Date: Jun 2005
Posts: 3,907 salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 153 Folding Title: Novice Folder
Time spent in forums: 2 Months 3 Weeks 4 Days 1 h 39 m 56 sec
Reputation Power: 1774
> "ISO C forbids nested functions"
Like the message says, nested functions are not part of ISO C.

GCC allows it (but then again, unconstrained GCC allows a lot of things).

Nested functions look like this
Code:
void foo ( ) {
    int bar ( ) {
        return 42;
    }
    int res = bar();
}


In ISO C, do this
Code:
int bar ( ) {
    return 42;
}
void foo ( ) {
    int res = bar();
}


The only issue is the scope of bar, which in the former case is just the foo function, and in the latter, its the whole file.
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper

Reply With Quote
  #3  
Old December 25th, 2012, 04:05 PM
littlerunaway littlerunaway is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 2 littlerunaway User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 51 sec
Reputation Power: 0
thanx

I actually did it correctly. just forgot a '}' in the end of main function. that's probably what caused the problem.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Nested functions

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap