Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>No, this won't work.</p> <p>First of all, all the definitions of the structure must be the same, otherwise you get the infamous Undefined Behaviour.</p> <p>Second, look at the memory layout. What should be the offset to <code>bar</code> from the beginning of the structure? The first and the third definitions don't agree on this (the fields are most likely to be located consecutively).</p> <p>Maybe you can try a union?</p> <pre><code>struct theStruct { int fd; unsigned int flags; struct config config; int foo; // in both systems union { int bar; // only in System A int foobar; // only in system B }; }; </code></pre> <p>If you choose this, you should use only <code>bar</code> on System A and only <code>foobar</code> on System B.</p> <hr> <p>If the two systems are incompatible, and the actual type needed for <code>bar</code> is not available on System B (and vice versa), you can do with the following code:</p> <pre><code>struct theStruct { int fd; unsigned int flags; struct config config; int foo; // in both systems #ifdef SYSTEM_A int bar; // only in System A #else #ifdef SYSTEM_B int foobar; // only in system B #else #pragma error(either SYSTEM_A or SYSTEM_B must be enabled) #endif #endif }; </code></pre> <p>This way you will be always working with either with code compiled for System A or for System B, so you'll need to have different executables (which seems to be unavoidable anyway if you are compiling for the systems so much different).</p> <p>You'll need to wrap parts of your code accessing the fields into <code>#ifdef</code>s:</p> <pre><code>#ifdef SYSTEM_A s.bar = 5; #endif </code></pre> <p>-- otherwise you'll get compile errors on System B.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload