ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
At first, I would like to thank both of you for your help.
From your replies I conclude to the fact that if the struct contains pointers, they count as 1 byte, but the struct to which they point is not included in the sizeof calculations.
Is there any other option to include also the size of the structs that are pointed from the pointers?
But, this is more a C++ question than a Linux question. Maybe I have to send it in another forum.
I think that yes, size of a pointer under normal circumstances is 4bytes, but he's specifying u_int8_t, and therefore if it's 1byte the sizeof call comes out right (and I'm sort of more inclined to trust c++ knowing what sizes its own types are than my own faulty memory )
The reason that you've got the size of each whole array represented as 1 byte is that you're acually getting at the size of the array identifier, which is -you said it- a pointer and therefore has the size of whatever you declared the array as. If you declared the array as being of type u_int8_t the "sizeof(array)" call will return sizeof(u_int8_32) which is 1byte.
However, if you want to get the total size of the struct plus the actual sum of all the elements in the arrays, my guess is you'll have to manually do the addition --
sizeof(*(foo.IPaddress)) + sizeof(*(foo.L2address)) + sizeof(*(foo.CoA)) ...I've no idea if that will work as written, but that's the idea
or just use a few for loops and get the size of all the elements....maybe there's a more elegant way out there, but I don't know it.
Edit: Yep, it's right. u_int8_t is an unsigned integer, length 8 bits. u_int32_t is 32 bits, also unsigned.
Last edited by rose_bud4201; 04-06-2005 at 01:40 PM.