Re: [OT][PB] if ( x = y ) mistake warning
Re: [OT][PB] if ( x = y ) mistake warning
- Subject: Re: [OT][PB] if ( x = y ) mistake warning
- From: Sailor Quasar <email@hidden>
- Date: Sun, 6 Jul 2003 15:10:39 -0400
On Sunday, July 6, 2003, at 02:43 PM, Bill Cheeseman wrote:
How can I turn on a warning for the mistake if ( x = y ) in Project
Builder?
How would Project Builder know it is a mistake? It's perfectly valid C
code.
It assigns y to x, then tests the result for nil or non-nil. This
locution
is used frequently in Cocoa init methods, where one generally writes:
if (self = [super init]) { ...
with a single equals sign. If the result is nil, it is documented to
mean
that the superclass failed to initialize itself.
I always write "if ((self = [super init])) {".
In my personal opinion, it wouldn't be right to have the compiler
generate a
warning for this. In general, I wouldn't want my compiler to become so
strict that it reminded me of good coding practices as opposed to
non-obvious potential errors. I suppose the dividing line is a matter
of
judgment or personal taste, but this one I wouldn't want.
I respectfully disagree. In my experience, using a single equals sign
in an if is Far more often an error than not, and in those cases which
aren't the compiler can be very easily silenced with an extra pair of
parenthesis. It is certainly valid C code, but outside the Cocoa -init
methods I do not generally see a large-scale use of it. I believe that
if others did not agree, the compiler warning would not exist at all to
be turned on. (Disclaimer: all IMHO :).
-- Sailor Quasar, just another player in The World
"Come with me in the twilight of the summer night for awhile"
Email: email@hidden
_______________________________________________
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.