rjohnson@shell.com (Roy Johnson) (04/17/91)
One more shot at this "problem": int v=1; int return_v() { return v; } int main() { printf("v=%d, v=%d\n", v++, return_v()); return 0; } it prints v=1, v=1 under Sun cc, and v=1, v=2 under GNU cc. Or how about using aliasing: int main() { int v=1, *pv=&v; printf("v=%d, v=%d", v++, *pv); return 0; } which prints v=1, v=2 under both compilers? Just beating a dead horse... -- =============== !You!can't!get!here!from!there!rjohnson =============== Feel free to correct me, but don't preface your correction with "BZZT!" Roy Johnson, Shell Development Company
jon@maui.cs.ucla.edu (Jonathan Gingerich) (04/18/91)
In article <RJOHNSON.91Apr17102824@olorin.shell.com> rjohnson@shell.com (Roy Johnson) writes: >One more shot at this "problem": > >int v=1; > >int return_v() { > return v; >} > >int main() { > printf("v=%d, v=%d\n", v++, return_v()); > return 0; >} I don't believe the following sequence is prohibited: evaluation of (0) args to return_v() evaluation of return_v s.p. between evaluation of call and call evaluation of v++ - reads v side effect of v++ - writes v using previous read call to return_v() - reads v ... This would make it undefined. >Or how about using aliasing: > >int main() { > int v=1, *pv=&v; > > printf("v=%d, v=%d", v++, *pv); > return 0; >} Again, read and separated write of the same location would make it undefined, and there are no s.p.'s in question - undefined. I believe any unordered asymetric operation combined with function calls (not macros!-) can be unspecified. int v=1; int bump_v() { return ++v; } int main() { ... (bump_v() - bump_v()) ... } Jon.