Archived

This topic is now archived and is closed to further replies.

This topic is 5700 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Lemme get straight to the point. I have a "struct" something like this struct TGAHEADER{ // blah // blah }; sorry, i dont have the exact code with me right now since i''m writing this from a cyber cafe. The thing is, when i count the size of TGAHEADER manually i get 18 bytes, but when i use sizeof(TGAHEADER) it gives 20 bytes !! ( I''m using MSVC++ 6.0 for your information ). Well.. this is aint a new thing for me though since i ran into a similar problem few months back in GCC compiler. God knows how many times i banged my head against the monitor until i came across this magical thing called "__attribute((packed))". Is there any such "__attribute((packed))" like thing in VC++. I know this is all about "structure data alignment" which could be fixed by changing the "Data Alignment" from Project->Settings->C++->Code Generation. But that''s gonna effect my whole project right ? Obviously i dont want to let ONLY ONE "struct" to effect my whole project. The funny things is, even if i change the data alignment, the compiler says: **warning: the data alignment is not consistent with the pre-compiled header so ignoring the /Z flag DUH ! WHAT DO I DO KNOW ? Anyone with better idea ?

Share this post


Link to post
Share on other sites

#pragma pack(push)
#pragma pack(1)
#define BYTE_ALIGN

struct YADAYADA
{
data...
data...
}BYTE_ALIGN;

#pragma pack(pop)
#undef BYTE_ALIGN



[edited by - Rickmeister on May 6, 2002 11:37:53 AM]

Share this post


Link to post
Share on other sites
This happens because your compiler is optimizing the struct so that it fits on a 32-bit alignment. Different compilers might not do this, but as long as you use sizeof, you should have no major problem.

-Doug

"Sometimes I think the surest sign that intelligent exists elsewhere in the universe is that none of it has tried to contact us" -Calvin

Share this post


Link to post
Share on other sites