I agree with you, in C# they had the good sense to enforce an evaluation order that is left to right. The C approach is inexcusable:@nsaspook,
I made a discovery today, dammit. Look at this code snippet:
It took me the day today to realize that the functions (as part of a mathematical expression) are not necessarily executed in the order as written.C://Send Data & checksum UART2_dataByte( -( UART2_dataWord(vtemp) + UART2_dataWord(vbias) + UART2_dataWord(vduty) + UART2_dataWord(vbatt) + UART2_dataWord(PID_getTarget()) + UART2_dataByte(PID_getLock()) + UART2_dataByte(getGainIndex()) ) );
My checksum was calculated properly, but the datastream was all mixed up.
I should have realized this as I wrote it, but my subconscious fully expected the code to be executed as written.
That's about as unhelpful as one can be as a language designer and is almost guaranteed to generate bugs. They didn't even let you use some keyword (like say ordered) to force an evaluation order either, at least that would be there for you when you needed it; and people wanted to write an operating system with this insanity? Jeez.The compiler will evaluate them in any order, and may choose another order when the same expression is evaluated again.
It's completely safe of course when all the operands are side-effect free, but that too is a rare thing in a language like C. Far too much is left either undefined or to the whim of the implementor with C, sloppy, sloppy, sloppy.