views:

40

answers:

2

Is this well defined?

Streamreader ^reader = gcnew Streamreader("test.txt");
String  ^line;

while ((line = reader->ReadLine()) != nullptr && line != "")
{
    //do stuff
}

I believe that I read somewhere that it is not guaranteed that the assignment is executed before the 2nd conditional. It may be that I'm wrong or that this just applies for C.
Google did not help me with this, that is why I am asking here :)

+3  A: 

With && and ||, it is guaranteed to evaluate the first condition (including the assignment) before evaluating the second condition.

With bitwise & and |, on the other hand, no such guarantees are made.

Eric Brown
+1  A: 

There is a related answer here with a number of good references: http://stackoverflow.com/questions/628526/is-short-circuiting-boolean-operators-mandated-in-c-c-and-evaluation-order

Short answer if you haven't overloaded && and || you'll get short-circuit evaluation, which goes from left to right. Take a look in the link.

Paul Rubel
randooom