------- Comment #5 from alexey at cs dot sunysb dot edu  2006-04-14 03:06 
-------
> > > It is undefined on which function call is done in what order
> > It does not matter in this example.
> Why do you think that?

Because the result is "x x x" for all orders instead of 1 2 3.

> int *a, *b, *c;
> c = func(3);
> b = func(2);
> a = func(1);
> 
>   printf("%d %d %d\n", *(a), *(b), *(c));

I understand and disagree that this is not a bug. Consider the following
example:

char *arr;
void read_input() {
  arr=malloc(10);
  read(fd, arr, 10);
}

void print_input() {
  if (!arr) printf ("input empty\n"); else 
  {   printf("%s\n", arr); free(arr); arr=NULL; }
}

go(read_input, print_input);

If the compiler "optimizes" go() call so that the first argument is not
evaluated completely then evaluates the second argument and finally completes
evaluation of the first argument after arr was freed, then it is a segfault.
However, the function is evaluated correctly if the arguments are evaluated
completely.


-- 

alexey at cs dot sunysb dot edu changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|DUPLICATE                   |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27153

Reply via email to