Re: void * pointer convert problem.




Christopher Benson-Manica wrote:
> I don't believe that's a portable assumption. The structures could
> have different padding bits, so unless key is the first element (in
> which case all is well, as structs can always be converted into a
> pointer to their first element),

So if I have:

struct s1 {
int id;
char *name;
int year;
};

struct s2 {
int id;
char *name;
int year;
time_t tstamp;
};

....
void *p;
struct s2 b;
....
p=&b;
((struct s1 *)p)->year=2000;
....

the last assignment may not be portable?

I may be wrong, but I think GTK+ is doing something similar.

.



Relevant Pages