48 ms·
Which version of C? The answers vary. For 1st ed. K&R, you're going to get implementation-specific behaviour, which might very well vary whether or not optimi
by bandy 14y ago
Which version of C? The answers vary. For 1st ed. K&R, you're going to get implementation-specific behaviour, which might very well vary whether or not optimization is enabled.
- jrajav 14y ago"Implementation-specific behavior [..] which might very well vary" In other words, the very definition of undefined behavior; You cannot reason about how the program will behave. This topic has already been covered fairly well on SO: http://stackoverflow.com/questions/949433/could-anyone-explain-these-undefined-behaviors-i-i-i-i-i-etc http://stackoverflow.com/questions/949433/could-anyone-expla...
- Someone 14y agoNot quite. C and C++ standards discriminate between undefined- and implementation-defined behavior. In the latter case, implementaitons can differ, but each must choose (and document) some well-defined way to handle a case. A trivial example is "sizeof(int)". The standard does not say much about what it produces (IIRC, it must be an int at least as large as sizeof(char)), so it can return 1, 2, 4, or even 17 (well, maybe not in C11. Newer standards tend to put more restrictions on behavior) A nontrivial example is the value of "-64 >> 3". More info at http://stackoverflow.com/questions/2397984/undefined-unspecified-and-implementation-defined-behavior http://stackoverflow.com/questions/2397984/undefined-unspeci... I think the post you reply to refers to the fact that early K&R C predates any standard that introduced the term 'undefined behavior'. At that time, the standard was just 'whatever that tool Kernighan and Ritchie wrote does'.
- bandy 14y agoEven at that point, there was the PDP-11 compiler and the compiler for the Perkins-Elmer implementation, not to mention the (straight) C compiler (/usr/bin/cc) vs the Portable C Compiler, both of which were available on V7. The maxim then (and now) being: Don't Write Silly Code.