This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
To get the size of a member of a struct
- From: Eus <eus at member dot fsf dot org>
- To: GCC Help Mailing List <gcc-help at gcc dot gnu dot org>
- Date: Thu, 17 Apr 2008 05:19:37 -0700 (PDT)
- Subject: To get the size of a member of a struct
- Reply-to: eus at member dot fsf dot org
Hi Ho!
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 is because I cannot do `sizeof(person->name)' or
`sizeof((struct person).name)'. Or, is there any other way to do so?
struct person
{
int id;
char name [50];
double salary;
};
int main (int argc, char **argv, char **envp)
{
printf ("sizeof(name) = %zd\n", sizeof(((struct person *) 0)->name));
exit (EXIT_SUCCESS);
}
Thank you very much.
Best regards,
Eus
____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ