This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

To get the size of a member of a struct


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]