On 08/16/2011 07:27 PM, Richard W.M. Jones wrote:
> Grrr now _my_ program has a bug.
>
> ----------------------------------------------------------------------
> #include <stdio.h>
> #include <stdlib.h>
>
> void f (int a, int b);
> int g (void);
> int *global = NULL;
>
> int
> main (void)
> {
> int x = 1;
> global = &x;
> f (g (), x);
>
> exit (0);
> }
>
> void
> f (int a, int b)
> {
> printf ("a = %d, b = %d\n", a, b);
> }
>
> int
> g (void)
> {
> if (global) {
> (*global)++;
> return *global;
> }
> else
> return 42;
> }
> ----------------------------------------------------------------------
>
> This program doesn't show undefined behaviour.
Undefined behaviour doesn't mean it must show different results with -O2,
it *might* if the compiler decides to do some optimization.
But isn't this 'f(g(), x)' issue the same as the classic example of undefined
behaviour with f(++i, ++i)?
Best regards,
--Edwin
--
Caml-list mailing list. Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs