Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

TotalLuck

macrumors newbie
Original poster
Jan 3, 2009
21
0
Moreno Vallley
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
 
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.
 
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
 
Ok yeah i understand syntax error.

should be

Code:
 int n;

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



thanks for the reply though
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.