Much belated declspec(align) part 2.

Jun 25, 2006 04:29

My "I'll finish this post tomorrow" turned into 5 months later. Oops. In my defense I was busy with many things, including a rewrite of my website backend. That lavish bit of over-engineering will no doubt be the topic of some future post ( Read more... )

Leave a comment

Comments 5

awong June 25 2006, 15:26:58 UTC
That is pretty screwy, but if you think about it a bit, I'm not sure if there's another way to handle it. If somehow the interaction managed stuff the padding in the first struct, S, then you'd end up with 2 different layouts for 1 struct, and essentiallly 2 different types.

Reply

thedutch June 25 2006, 22:02:12 UTC
I think you COULD honor the pragma pack then fixup the alignment by padding as high in the structure as possible. It seems like a reasonable way to think resolving it procedurally. But inheriting the alignment requirement to S (and correspondingly to T) is a better language rule, and enough to ensure that everything is correct.

Even if the result is a little messy, at least the rule is elegant!

Reply

awong June 26 2006, 03:14:14 UTC
it already is padded as high as possibel though, It hink... C does infact guarantee that hte first element of a struct is at the beginning of that struct.

Reply

thedutch June 26 2006, 04:14:50 UTC
This example is, but we could imagine an alternate (bad) packing methodology in the general case. It's interesting to me that they had the forsight to allow such a wide variation in the packing schemes of structures. You can throw padding all over the place!

Really I hadn't considered other possible legal packings of the structure, just other mothodologies to arrive at the correct packing and alignment.

Reply


travisezell June 25 2006, 18:19:20 UTC
Dutch, you're so right.

Reply


Leave a comment

Up