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.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
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 02:40 PM.