Re: [chrony-dev] GCC issue

[ Thread Index | Date Index | More chrony.tuxfamily.org/chrony-dev Archives ]


On Tue, 21 Jan 2014, Dale R. Worley wrote:

From: Bill Unruh <unruh@xxxxxxxxxxxxxx>

Apparently there is no sequence point with the | operator and the
compiler is free to use any order.

http://en.wikipedia.org/wiki/Sequence_point

Lets hope that
r=(fprintf()<0) ;
r|=fclose()
does not get optimized away by the compiler, and then one runs into the same
problem.

My understanding is that the fclose() is required to be executed
regardless of the value of r at that point -- "|" is not a
short-circuit operator.

I would like to see the code as:

r=(fprintf()<0) ;
r|=(fclose() == EOF);

fclose() returns 0 on success and EOF on failure, and it's generally
not a good idea to use "|" on values whose bit-pattern you do not
understand.

But with the bitwise or, if ANY bit is non zero, the result is nonzero, which
is what you want. So in this case it is fine. No matter what fclose returns,
unless it is zero it is an error.



Dale



--
William G. Unruh   |  Canadian Institute for|     Tel: +1(604)822-3273
Physics&Astronomy  |     Advanced Research  |     Fax: +1(604)822-5324
UBC, Vancouver,BC  |   Program in Cosmology |     unruh@xxxxxxxxxxxxxx
Canada V6T 1Z1     |      and Gravity       |  www.theory.physics.ubc.ca/

--
To unsubscribe email chrony-dev-request@xxxxxxxxxxxxxxxxxxxx with "unsubscribe" in the subject.
For help email chrony-dev-request@xxxxxxxxxxxxxxxxxxxx with "help" in the subject.
Trouble?  Email listmaster@xxxxxxxxxxxxxxxxxxxx.


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/