A little disappointed so far
Jeff Epler
jepler at unpythonic.net
Mon May 19 13:27:36 EDT 2003
On Mon, May 19, 2003 at 11:10:41AM -0600, Daniel Fackrell wrote:
> ----
> #include <stdio.h>
> int main() {
> int x;
> x = 0;
> x = ++x + ++x + x++ + x++; // This is legal C code, but what does it do?
> printf("x is %d", x);
> return 0;
> }
> ----
> gcc under Cygwin/Linux: "x is 10"
> cc on HPUX: "x is 8"
> gcc under HP/UX: "x is 3"
>
> Just as a note, there were no warnings or errors while compiling.
This is syntactically valid C code, but the standard specifically states
that it produces undefined results.
And, I should note, I *do* get compiler errors on this program:
$ gcc -Wall -ansi -pedantic fackrell.c
fackrell.c: In function `main':
fackrell.c:5: warning: operation on `x' may be undefined
fackrell.c:5: warning: operation on `x' may be undefined
fackrell.c:5: warning: operation on `x' may be undefined
fackrell.c:5: warning: operation on `x' may be undefined
fackrell.c:5: parse error before '/' token
Jeff
More information about the Python-list
mailing list