bad function ptrs - is it dangerous ?
Quoted 8 lines · J.A. Magallon
int (*pf)(data *);
intf(data*);so you can:
pf = f;
pf(data).
Quoted 7 lines
Fine. But what happens if:
void (*pf)(data *);
intf(data*);pf = f; // gcc happily swallows, gcc-3.2 gives a warning. pf(data).
Undefined Behaviour. I can easily imagine cases where, depending on the calling convention and the actual return type, things could go very very wrong. Consider struct returns...
This case, returning an int to a caller expecting void, is likely to work on most normal machines -- the int would go into a GP result register, and the GP result register is typically always part of the caller-save set. The code is still utter crap, however.
Quoted 2 lines
The (in)famous graphics driver all you know is doing this with the
copy_infoop for gart...
<censored>
/Mikael