1

Here's the assert. In what reasonable circumstances can it fail, and why is the game checking it?

Max Yankov
  • 12,551
  • 12
  • 67
  • 135

2 Answers2

5

Some platforms define bool to be the same size as int. At least older versions of Mac OS X (and likely other RISC BSD ports) were like this. Presumably the code uses bool arrays with an assumption of efficiency. Doom has been ported to a lot of platforms so it's probably very cagey about such things.

It has to be done at runtime because there is no standard macro specifying sizeof(bool), and compile time checks didn't work with non-macro expressions until C++11.

Potatoswatter
  • 134,909
  • 25
  • 265
  • 421
  • Thanks! But why does it rely on the bool's size? – Max Yankov Jan 05 '14 at 04:47
  • @golergka If it's creating very large arrays, then substituting `int` for `char` will cause a bloated memory requirement and hurt performance. Not to mention the possibility of throwing off address arithmetic which may be strictly noncompliant to the standard. – Potatoswatter Jan 05 '14 at 04:48
  • "Some platforms define bool to be an int" - bool is an inbuilt type and never "defined" to be anything else, though the size of a bool may be the same as that of an int. – Tony Delroy Jan 05 '14 at 04:54
  • 1
    "t has to be done at runtime" appears to be incorrect. E.g., in C++98 you could just `typedef char static_assert_goodbool[(sizeof(bool)==1)? 1 : -1]`. I write "appears to" because maybe you're referring to some internal Doom-specific thing? – Cheers and hth. - Alf Jan 05 '14 at 06:16
  • @Cheersandhth.-Alf Eh, yes, there is that, but it's fair to say there is no *facility* for compile time checks on non-macros. The runtime check is more reasonable in C++03 than it would be in C++11. – Potatoswatter Jan 05 '14 at 06:22
1

I think I have come across the the answer you were looking for. Doom 3 is cross platform and on x86 platforms bool is defined by gcc with a size of 1. In gcc(compiler used by Apple at the time),on Mac OS X PowerPC on the other hand it defaults to 4. Use the -mone-byte-bool to change it to 1.

From http://linux.die.net/man/1/g++

  -mone-byte-bool
       Override the defaults for "bool" so that "sizeof(bool)==1".  By
       default "sizeof(bool)" is 4 when compiling for Darwin/PowerPC and 1
       when compiling for Darwin/x86, so this option has no effect on x86.

       Warning: The -mone-byte-bool switch causes GCC to generate code
       that is not binary compatible with code generated without that
       switch.  Using this switch may require recompiling all other
       modules in a program, including system libraries.  Use this switch
       to conform to a non-default data model.
jeisom
  • 11
  • 1