|
![](/i/fill.gif) |
"Philippe Lhoste" <Phi### [at] GMX net> wrote:
> If I want to do:
> if (f = Foo())
> to check if Foo is not returning an error status, I should instead write:
> if ((f = Foo()) != 0)
> which is uglier, but less prone to errors or ambiguity.
>
> I know that some coders prefer to write:
> if (Foo() == f)
> because if they forget an equal, an error will be thrown. But I don't like
> much this form, habits, you know?
>
> BTW, I write now:
> f = Foo();
> if (f != 0)
> which is more elegant, easier to read, and probably as efficient.
Yes, it is generally as efficient. And clear. I tend to use this form most
of the time as well...
BTW, there's one more way to express that same thing and not to cause any
warning messages:
if((f=Foo()))
Post a reply to this message
|
![](/i/fill.gif) |