0

I remember seeing some C code which would fail to compile if a condition was false at compilation time. I cannot remember where I saw it.

In particular, I am writing some non-portable C code which should only compile where the target's sizeof(int) == 4. i.e. 32 and 64 bit Linux, but only 32 bit Windows, IIRC.

fadedbee
  • 42,671
  • 44
  • 178
  • 308
  • 1
    `int` has 32 bits on win64 as well, see [64-bit data models](https://en.wikipedia.org/wiki/64-bit_computing#64-bit_data_models) –  Apr 03 '18 at 09:53
  • 1
    get inspired from here: https://stackoverflow.com/questions/9229601/what-is-in-c-code – bolov Apr 03 '18 at 09:54
  • btw, not what you're asking, but is there really a need for such code nowadays? Any decent C compiler should provide e.g. `int32_t` on a platform that *has* a 32bit integer available .... (so, using it, the compiler will error out "for free" if your platform really *doesn't* have one) –  Apr 03 '18 at 09:57
  • 1
    `#define check_condition(x) { int array[x? 1 : -1]; } ` or zillion other ways. – n. m. could be an AI Apr 03 '18 at 09:59
  • @FelixPalmen I'm writing non-portable code which deals with bit fields containing both `uint32_t`s and `enum`s which need to all form a single `uint32_t` in a `struct`. – fadedbee Apr 03 '18 at 09:59

0 Answers0