aed@netcom.COM (Andrew Davidson) (06/26/91)
Hi
here is a piece of code I am responceible for maintaining. It compiles
and runs correctly on the sun and dos using the msc 5.1 compiler
if (! ((tt = testEntry.code - testCode) || (tt = testEntry.leg -
testLeg)))
{
....
}
does the language guarentee that if testEntry.code -testCode is not
equal to 0, that the second assignment (tt = testEntry.leg - testLeg)
will not be executed?
will the -O compiler option flag effect this??
thanks Andy
P.S
personaly I would rewite this, but the orginal author will not allow my.
--
-----------------------------------------------------------------
"bede-bede-bede Thats all Folks"
Porky Pig
Andrew E. Davidson
andy@cats.com
aed@netcom.COM
-----------------------------------------------------------------
kremer@cs.odu.edu (Lloyd Kremer) (06/26/91)
In article <1991Jun25.235904.23103@netcom.COM> aed@netcom.COM (Andrew Davidson) writes: > >if (! ((tt = testEntry.code - testCode) || (tt = testEntry.leg - >testLeg))) > { > .... > } > >does the language guarentee that if testEntry.code -testCode is not >equal to 0, that the second assignment (tt = testEntry.leg - testLeg) >will not be executed? Yes. To compiler writers the || symbol in this statement is a sequence point and the expression to its right may or may not be evaluated (i.e. the code to evaluate it may or may not be executed) depending on the result of the of the expression to its left. (That's the way it stacks up for this particular statement anyway.) The code here will use the first expression if it is non-zero, else use the second expression; but if both are zero enter the "if" block. Lloyd Kremer Hilton Systems, Inc. kremer@cs.odu.edu
simonp@fulcrum.bt.co.uk (Simon Parsons) (06/26/91)
>>>>> On 25 Jun 91 23:59:04 GMT, aed@netcom.COM (Andrew Davidson) said:
Andrew> Hi here is a piece of code I am responceible for maintaining.
Andrew> It compiles and runs correctly on the sun and dos using the msc
Andrew> 5.1 compiler
Andrew> if (! ((tt = testEntry.code - testCode) || (tt = testEntry.leg
Andrew> - testLeg))) { .... }
Andrew> does the language guarentee that if testEntry.code -testCode is
Andrew> not equal to 0, that the second assignment (tt = testEntry.leg
Andrew> - testLeg) will not be executed?
YES
Andrew> will the -O compiler option flag effect this??
I hope not!!!
Simon
--
"Hey girl, as I've always said, I prefer your lips red,
Not what the good lord made, but what he intended."
Simon Parsons, Fulcrum Communications Ltd.- simonp@fulcrum.bt.co.uk
wreck@fmsrl7.UUCP (Ron Carter) (06/27/91)
In article <1991Jun25.235904.23103@netcom.COM> aed@netcom.COM (Andrew Davidson) writes: >if (! ((tt = testEntry.code - testCode) || (tt = testEntry.leg - >testLeg))) > >does the language guarentee that if testEntry.code -testCode is not >equal to 0, that the second assignment (tt = testEntry.leg - testLeg) >will not be executed? Yes. Short-circuiting of logical operations is guaranteed by C. f o d d e r
mouse@thunder.mcrcim.mcgill.edu (der Mouse) (06/28/91)
In article <1991Jun25.235904.23103@netcom.COM>, aed@netcom.COM (Andrew Davidson) writes: > here is a piece of code I am responceible for maintaining. > if (! ((tt = testEntry.code - testCode) || (tt = testEntry.leg - testLeg))) > does the language guarentee that if testEntry.code -testCode is not > equal to 0, that the second assignment (tt = testEntry.leg - testLeg) > will not be executed? Yes. > will the -O compiler option flag effect this?? No, the code generator should effect it. The -O flag will not *affect* it (this aspect of it, at least) unless the compiler is badly broken. > personaly I would rewite this, but the orginal author will not allow > my. If you're maintaining it, it's your business, nay, your *duty* to make changes like that that you feel will improve the code. (If you make such judgements incorrectly, you're a bad choice as maintainer. In this case I don't think you'd be wrong.) I assume this conflict between supposed responsibility and actual privilege is imposed; you'll have to decide whether it's worth making a fuss over.... der Mouse old: mcgill-vision!mouse new: mouse@larry.mcrcim.mcgill.edu