delorie.com is funded by banner ads.
  www.delorie.com/djgpp/v2faq/faq182.html   search  

| Previous | Next | Up | Top |

22.11 C++ doesn't pack structs!

Q: When I use struct ffblk from the header dir.h in a C++ program, I get garbage in some members of the structure!


A: There is a known bug in GCC 2.7.2: the C++ compiler effectively ignores the __attribute__((packed)) directives, so the structures end up being not packed. DJGPP v2.01 comes with GCC 2.7.2.1 which corrected that bug, so upgrade. As a work-around, surround the declaration of the structure that needs to be packed with #pragma pack, like this:
       #ifdef __cplusplus
       #pragma pack(1)
       #endif
       .
       .
       .
       #ifdef __cplusplus
       #pragma pack()
       #endif


  webmaster   donations   bookstore     delorie software   privacy  
  Copyright ⌐ 1998   by Eli Zaretskii     Updated Sep 1998  

Powered by Apache!

You can help support this site by visiting the advertisers that sponsor it! (only once each, though)