To get the size of a member of a struct

Jim Wilson wilson@tuliptree.org
Fri Apr 18 19:52:00 GMT 2008


Eus wrote:
> Is `sizeof(((struct person *) 0)->name)' the proper way to retrieve the size of a
> member of a struct without declaring a variable of that struct as demonstrated in
> the program below?

It should work, but may not be the best solution.

Another solution is to define a type you can query, e.g. 

typedef char name_t[50];
and then use this in the struct definition and in the sizeof call.

Jim



More information about the Gcc-help mailing list