Nested functions disabled

Discussion in 'iOS Programming' started by TotalLuck, Jul 9, 2009.

  1. TotalLuck macrumors newbie

    TotalLuck

    Joined:
    Jan 3, 2009
    Location:
    Moreno Vallley
    #1
    I am trying to follow the stanford itunes classes.

    As i am watching the lectures, ( which are from this year), they are using examples with nested functions.

    However everytime i try to do a simple nested function i get an error that says to use -fnested -function to enable them.
    such as this is good
    Code:
    - (IBAction)increaseNumOfSides 
    {
        NSLog(@"im in the increase action"); 
    	int n = myPoly.numberOfSides;
    	++n;
    	[myPoly setNumberOfSides: n];
    	[self updateInterface];
    }
    
    instead of allowing this
    Code:
    - (IBAction)increaseNumOfSides 
    {
        NSLog(@"im in the increase action"); 
    	int n += myPoly.numberOfSides;     //  this is not allowed
    	[myPoly setNumberOfSides: n];
    	[self updateInterface];
    }
    
    In this case its such a small amount of code to write i don't really care, however its annoying.

    My question is really, why are they disabled in the first place. what problem does nesting your functions cause that Apple recommends that they stay off.

    and i have searched the forum and looked to turn them on but i cant seem to find the "other c flags" in xcode to do that. i have gone to the target build menu but i dont see that flag area to put the code in. i am using xcode 3.1.2

    any thoughts anyone?

    Greg
     
  2. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #2
    Nested functions are not a part of standard C. They are a GCC language extension. You can find out more about them with Google. I would personally never use them.

    I don't think a line like

    int n += 5;

    is a nested function. I think it's just a syntax error.
     
  3. TotalLuck thread starter macrumors newbie

    TotalLuck

    Joined:
    Jan 3, 2009
    Location:
    Moreno Vallley
    #3
    nested functions

    Ok yeah i understand syntax error.

    should be

    Code:
     int n; 
    then i can do
    Code:
     n += myPoly.numberOfSides; 


    thanks for the reply though
     
  4. kalimba macrumors regular

    Joined:
    Jun 10, 2008
    #4
    You really shouldn't do what those two lines of code do without initializing 'n' to some known value between them. Most compilers will emit a warning that you're using 'n' without first initializing it, or something to that effect.
     

Share This Page