• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: unused variable warnings
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: unused variable warnings


  • Subject: Re: unused variable warnings
  • From: "Clark S. Cox III" <email@hidden>
  • Date: Wed, 12 Feb 2003 10:21:29 -0500

On Wednesday, Feb 12, 2003, at 10:05 US/Eastern, 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];

Are you actually using somestring or today later in the code?


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];

That is because those variables are now used. Remember that assignment and initialization are two completely different things.

int foo = 0; //foo is initialized to the value zero (this does not count as "using" the variable)

int bar; //bar is initialized to an unknown value
bar = 0; //bar is assigned the value zero (this does counts as "using" the variable)
_______________________________________________
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.
  • Prev by Date: unused variable warnings
  • Next by Date: OmniWeb and AppleEvents
  • Previous by thread: unused variable warnings
  • Next by thread: Re: unused variable warnings
  • Index(es):
    • Date
    • Thread