Hello,
My C is a bit rusty, and coming from .Net I am bound to do some stupid things... Could anyone explain why declaring pointers isn't allowed in a switch statement?
Here's my code:
So how come I cannot declare a pointer in my switch statement? I bet $DEITY is killing kittens when I try declaring variables in there, but I'm a bit lost here...
Bonus question :
Let's suppose I were to develop using a custom gui toolkit for an undisclosed embedded device, and would like to change the text of a IUBoutonArrondi by calling :
Am I responsible for freeing the NSString* passed as an arg?
Here's what I am currently doing:
I guess Java/.Net really spoiled me on the memory management side of programming.
Thanks for your help, insight, and your surrender-monkey jokes.
My C is a bit rusty, and coming from .Net I am bound to do some stupid things... Could anyone explain why declaring pointers isn't allowed in a switch statement?
Here's my code:
Code:
NSString* outerScope=nil;
switch(myEnum){
case kMyValue1:
NSString* innerScope=@"InnerScope"; // Generates an error: unexpected token '*'
outerScope=@"OuterScope"; // works
for(int i=0;i<2;i++){ // works and also declares a variable in the statement
NSLog(@"declared i and iterates over it... %d",i);
}
break;
case kMyValue2:
// and now for something completely different
break;
}
So how come I cannot declare a pointer in my switch statement? I bet $DEITY is killing kittens when I try declaring variables in there, but I'm a bit lost here...
Bonus question :
Let's suppose I were to develop using a custom gui toolkit for an undisclosed embedded device, and would like to change the text of a IUBoutonArrondi by calling :
Code:
IUBoutonArrondi definirTitre:(NSString*) pourEtat:(int)
Am I responsible for freeing the NSString* passed as an arg?
Here's what I am currently doing:
Code:
NSString* str = [[NSString alloc] initWithCString("Bonjour Monde")];
[leMagnifiqueBouton definirTitre:str pourEtat:0x1]; //assign the text to the widget
// cleanup
[str release]; // do I need to do this? What if str was assigned a const as in str=@"foo";
I guess Java/.Net really spoiled me on the memory management side of programming.
Thanks for your help, insight, and your surrender-monkey jokes.