size of structure

I was going through random reading and i hit a page which says that the size of a structure in C can be "greater than" or equal to sum of sizes of its member. Plz can someone explain in which case its size is greater that sum of its member. Thanks in advance.
For efficiency reasons, sometimes a structure will have blank space or 'padding' inbetween its data members, to align the members to certain byte addresses, allowing for faster access. Its not something that will necessarily happen, but if the compiler decides that your program will run better because of it, it can. Hence, the only way to accurately determine the size of a structure is to use the sizeof operator.

What NT3 said, although I would word it as "for performance reasons", because I personally think of efficiency in terms of space, not time.

Padding helps the CPU retrieve the data faster.

Edit: third link added.
Last edited on
Thanks NT3. one more question. Is there a way we can manually create such paddings or is it only compiler who controls these free spaces?
Thanks catfish666 for those links.
Topic archived. No new replies allowed.