R
REH
Given that the standard guarantees that all pointers to struct are the
same size and representation, and that the same is true for all
function pointers, is this snippet of (contrived) code portable?
typedef struct t1 {int i;} t1;
typedef struct t2 {double d;} t2;
t1* f1() {static t1 x; return &x;}
t2* f2() {static t2 x; return &x;}
struct T;
typedef struct T T;
typedef T* (*F) ();
void foo(T** t, F f) {*t = f();}
int main()
{
t1* p1;
t2* p2;
foo((T**) &p1, (F) f1);
foo((T**) &p2, (F) f2);
return 0;
}
REH
same size and representation, and that the same is true for all
function pointers, is this snippet of (contrived) code portable?
typedef struct t1 {int i;} t1;
typedef struct t2 {double d;} t2;
t1* f1() {static t1 x; return &x;}
t2* f2() {static t2 x; return &x;}
struct T;
typedef struct T T;
typedef T* (*F) ();
void foo(T** t, F f) {*t = f();}
int main()
{
t1* p1;
t2* p2;
foo((T**) &p1, (F) f1);
foo((T**) &p2, (F) f2);
return 0;
}
REH