K
Keith Thompson
Tony said:I remember seeing something that left me with the impression that C (C++?)
guarantees that a struct will be aligned on a pointer-size boundary (using
the std mem mgr). (?) Something about 4-byte struct alignment (on a 32-bit
machine no doubt) sticks in my mind.
You remember incorrectly. There's no rule in C (or C++) about the
relationship between the alignment requirements for structs and
those for pointers. You may have seen something about a specific
implementation.
There is a rule that all pointers to structs have the same size
and alignment, but that refers to the pointer objects themselves,
not to the structs.
People in this thread have been asking the original poster why he's
concerned about alignment. You've been jumping in and "defending"
him, suggesting reasons he might care about it. I suggest you wait
for the OP himself to give his reasons. If he actually has specific
reasons, we can help him -- and knowing just why he's concerned about
alignment can help us to help him. But it's also quite possible
that he wrongly thinks he needs to worry about alignment, and that
in fact he can largely ignore the issue and still get working code.