Re: Compiler flagging = v. ==
Re: Compiler flagging = v. ==
- Subject: Re: Compiler flagging = v. ==
- From: j o a r <email@hidden>
- Date: Thu, 11 Mar 2004 07:44:30 +0100
The warning is suggesting that you should use parentheses around the
*assignment*, inside the parentheses for the evaluation of the truth
value. Like this:
if ((err = 0)) err = 1;
This syntax makes a bit of sense. First evaluate the stuff inside the
inner parentheses, then try to interpret the result of that evaluation
as a truth value. A common example from Cocoa+ObjC is this:
NSEnumerator *enumerator = [someArray objectEnumerator];
id obj;
if (obj = [enumerator nextObject]) {}
...that should be turned into:
if ((obj = [enumerator nextObject])) {}
...or even better (IMO):
if ((obj = [enumerator nextObject]) != nil) {}
j o a r
On 2004-03-10, at 22.20, Randall Meadows wrote:
> Well, I did see that, actually, but I'm not omitting parens, I'm
> omitting an equal sign, so it didn't seem apropos. Although it is
> true that I have "an assignment in a context where a truth value is
> expected".
>
> The error message is a little odd (given my perspective, not the
> doc's) with the code:
>
> if (err = 0) err = 1;
>
> the message is "warning: suggest parentheses around assignment used as
> truth value"; I have parens, so why is it suggesting I use parens?
[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
xcode-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/xcode-users
Do not post admin requests to the list. They will be ignored.