2 ms·
C has undefined, unspecified and implementation-defined behavior in those places where there was no implementation consensus 35 years ago; it's just maintaining
by kazinator 8y ago
C has undefined, unspecified and implementation-defined behavior in those places where there was no implementation consensus 35 years ago; it's just maintaining the status quo.
The thing that were and were not codified as requirements in 1989 ANSI C were a historic accident of the time; now that historic accident is just being preserved, more or less.
E.g. we must have unspecified evaluation order of function arguments because we've always had unspecified evaluation order of function arguments.
- MaxBarraclough 8y agoI'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?