To get the size of a member of a struct

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux