87023RE: swap word
- Feb 1, 2008
>>'Though if this is C, you might wanna cast the NULL to whatever pwarning
>>happens to be, so something like
>> (const char *)NULL == p
>> (struct foo *)NULL == p
>> (FILE *)NULL == p
>> (void *)NULL == p
>>etc., if it's a pointer to character data, a struct, a file, or a
>>generic nothing. Fwiw...
>>And I happen to turn on *all* warnings, so even leaving it as-is will
>>trigger the "possible assignment in conditional" or whatever the
>>would be, in the compiler stage.Well, yeah, but the *reason* you do it "backwards", ie, compare the
>I hope not! It's not an assignment, it's a comparison. It has == not =.
constant with the variable instead of the variable to the constant, is
in case you accidentally forget one '=', a newbie mistakee, but hey,
typos happen... So mistyping it as
if( p = NULL )...
will quietly assign NULL to p, finish the compilation and hand you the
compiled executable just fine, but that if() will always be false, and
the condition will never be taken, as well as irreparably munging p,
obviously a bug. But having
if( NULL = p )...
will try to assign the value of p to a constant, a clear error, and
*not* let you go beyond that. So you see the error, wonder "Wtf
happened?? Oh, forgot the 2nd '='... silly me.", fix it, recompile, and
everyone's happy. :D
I was never crazy about assigning things "backwards", so I still do it
if( p == (whatever)NULL )...
way, only I turn on practically every allowable warning in existence. I
got nicknamed "the human 'lint'" for casting practically *everything* to
make sure there was absolutely no misinterpretation of what I was
Hey, worx for me...
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
- << Previous post in topic