Posted Apr 17, 2012 20:24 UTC (Tue) by jzbiciak
(✭ supporter ✭
In reply to: Not Again
Parent article: PHP: a fractal of bad design (fuzzy notepad)
Yep, and that bit me when I ported Doom to one of our DSPs. The code used the idiom P_Rand()-P_Rand() all over the place to get signed random numbers that were roughly normally distributed. GCC evaluated left-to-right, DSP compiler right-to-left.
While it wouldn't really affect the game play much, it was enough of a change that the prerecorded demo loops didn't function properly, because they expected the engine to be 100% deterministic. Once I found and fixed this error, they started working.
C is predictable when your program is bug free and relies on no implementation defined, unspecified or underspecified behavior. Such a program is extremely tedious to write, and next to impossible even for experienced practitioners. That's because implementation defined behavior is pervasive and useful.
I remember coming across a long, tiresome thread in comp.lang.c once where the goal was to bit-reverse a large integer array in 100% portable ANSI C. I don't recall if anyone succeeded, but the thread went far longer than I expected. Everyone made subtle assumptions about the environment, despite the guarantee that unsigned int is at least guaranteed to provide modulo-wraparound 2s complement arithmetic.
to post comments)