3 ms·
I'll ramble about the evaluation order thing: I presume the reason the C standards folks refuse to mandate left-to-right evaluation order is that it might cause
by MaxBarraclough 8y ago
I'll ramble about the evaluation order thing: I presume the reason the C standards folks refuse to mandate left-to-right evaluation order is that it might cause trouble for some arcane embedded compiler somewhere, or something.
The original intention was to enable optimisations, after all. If you do
make_coffee( get_barista(), get_beans() );
then if your target platform uses a stack-based calling convention, you'll want to do those two 'inner' calls in a certain order (depending on whether it's a 'reversed' stack-based calling convention or not).
If you're passing by registers, it will presumably make no difference.
It's a pretty wacky micro-optimisation by anyone's standards, and allows strange platform-specific bugs to arise, but I presume the refusal to specify evaluation order is just the standards body exhibiting a healthy resistance to changing the very stable C language. They don't want to cause a downside for anyone, even the strangest half-baked compilers.
- kazinator 8y agoThey could specify that there are exactly two possible evaluation orders (left-right or right-left) the choice of which is implementation-defined (must be documented) and that there is a sequence point between the evaluations of the argument expressions. (As well as between evaluating the function designating expression and the arguments.) The fact that there are N! possible evaluation orders for N argument expressions: which implementation does that serve? Or that there is no sequence points: which calling convention does that serve?