title: Exporting Packed structures with bool
body: <p>What is the best practice for exporting a packed structure containing booleans?</p>
  
  <p>I ask this because I'm trying to find the best way to do that. Current I do:</p>
  
  <pre><code>#ifndef __cplusplus
  #if __STDC_VERSION__ &gt;= 199901L
  #include &lt;stdbool.h&gt;    //size is 1.
  #else
  typedef enum {false, true} bool; //sizeof(int)
  #endif
  #endif
  </code></pre>
  
  <p>now in the above, the size of a boolean can be 1 or <code>sizeof(int)</code>..</p>
  
  <p>So in a structure like:</p>
  
  <pre><code>#pragma pack(push, 1)
  typedef struct
  {
      long unsigned int sock;
      const char* address;
      bool connected;
      bool blockmode;
  } Sock;
  #pragma pack(pop)
  </code></pre>
  
  <p>the alignment is different if using C compared to C99 &amp; C++. If I export it as an integer then languages where boolean is size 1 have alignment problems and need to pad the structure.</p>
  
  <p>I was wondering if it would be best to typedef a bool as a char in the case of pre-C99 but it just doesn't feel right.</p>
  
  <p>Any better ideas?</p>