Re: Avoiding == and = mixup in if statements
Re: Avoiding == and = mixup in if statements
- Subject: Re: Avoiding == and = mixup in if statements
- From: Nicko van Someren <email@hidden>
- Date: Fri, 21 May 2004 04:03:57 +0100
On 21 May 2004, at 3:10, Christoffer Lerno wrote:
Java disallows stuff like
if (myObject=nil) { dosomething }
Is it possible to maybe disallow the same potential error when I'm
writing obj-c programs? Could I do something with the pre-processor
perhaps?
Yes, sort of. You can add -Wparentheses to make the compiler warm you
when you write if (a=b)... and you'll get the message "warning: suggest
parentheses around assignment used as truth value". If it is really
what you meant you can say if ((a=b))... instead. This will also
happen if you use the more general flag -Wall. For production code
it's often a good plan to include -Werror in the C flags, so that the
code will not compile when there are outstanding warnings, but it can
become very irritating during initial development phases.
Nicko
_______________________________________________
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.