Re: unused variable warnings
Re: unused variable warnings
- Subject: Re: unused variable warnings
- From: Phrygian <email@hidden>
- Date: Wed, 12 Feb 2003 11:49:06 -0500
On Wednesday, February 12, 2003, Lindsey Spratt said:
>
On Wednesday, February 12, 2003, at 09:05 AM, Phrygian wrote:
>
>
> Hello Cocoa Programmers,
>
>
>
> I'm at a loss as to why I keep getting an "unused variable" compiler
>
> error in project builder under the following conditions,
>
>
>
> NSString * somestring = @"this is a string"; or NSCalendarDate *
>
> today = [NSCalendarDate calendarDate];
>
>
>
> the compiler will give a warning that somestring and today are
>
> unused variables. However, if I do the following,
>
>
>
> NSString * somestring; somestring = @"this is a string";
>
>
>
> or
>
>
>
> NSCalendarDate * today; today = [NSCalendarDate calendarDate];
>
>
>
> all is well.
>
>
It looks to me like the warning is correct in the first case,
>
'somestring' and 'today' *are* unused (and the compiler should have
>
given you a warning in the second case, but it's not that
>
sophisticated). Why create a variable that you never reference?
>
>
> Lindsey Spratt
>
http://homepage.mac.com/lspratt
>
_______________________________________________ cocoa-dev mailing list
>
| email@hidden Help/Unsubscribe/Archives:
>
http://www.lists.apple.com/mailman/listinfo/cocoa-dev Do not post
>
admin requests to the list. They will be ignored.
Yeah, the message would be correct, come to think of it. I do plan to use
variables I create -- just trying to figure out exactly what the message meant
since Codewarrior didn't give the same messages project builder did. If I ran in
the debugger, just for kicks, the string object nor the NSCalendarDate object
show up, i.e.,
(gdb) po somestring
No symbol "somestring" in current context.
I did just put a line in that "uses" the variable,
NSCalendarDate * now = [today copy];
and now the variable today is being used, but now isn't. Ok, this makes sense
now. This must be a built in smart feature of the ObjC compiler to not allocate
memory for variables that aren't used.... I'll have to dig through the compiler
documentation to confirm.
Thanks Lindsey.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.