Yuri Pudgorodsky writes:
 > 
 > > We can say something like:
 > >
 > > "In GNU C, you may cast a function pointer of one type to a function
 > > pointer of another type.  If you use a function pointer to call a
 > > function, and the dynamic type of the function pointed to by the
 > > function pointer is not the same as indicated by the static type of the
 > > function pointer, then the results of the call are unspecified.  In
 > > general, if the types are not too different 

s/not too different/compatible/

"not too different" has no meaning, whereas "compatible" is defined in
Section 6.2.7.

So,

 "In GNU C, you may cast a function pointer of one type to a function
 pointer of another type.  If you use a function pointer to call a
 function, and the type of any of the arguments to the function being
 called is not compatible with the type of the corresponding argument
 being passed, then the results of the call are undefined."


We need to do this because we use type-based alias analysis in gcc.
Imagine this scenario:

void poo (type_a *A, type_b *B)
{
  ...
}   

The compiler knows that if types type_a and type_b are incompatible,
they cannot alias, and takes advantage of that fact.  So, for example,
references to A and B might be reordered.  If we permit incompatible
types to be casted in function calls, we make a hole in alias
analysis.

Imagine this usage:

type_a *A1, *A2;

fptr fun = (fptr)foo;
(*fun)(A1, A1);

Andrew.

Reply via email to