www.delorie.com/djgpp/v2faq/faq22_12.html   search  
Node:Struct packing, Next:, Previous:Struct size, Up:Miscellany

22.12 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. GCC versions 2.7.2.1 and later 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 2001   by Eli Zaretskii     Updated Apr 2001