Abdelrazak Younes <[EMAIL PROTECTED]> writes:
> > | > (the warning was:
> > | > ..\..\lyx-devel\src\lyxtextclass.C(1065) : warning C4800: 'int' :
> > | > forcing value to bool 'true' or 'false' (performance warning)
> > | > )
> > Why is it a performance warning?
> Because you loose precision: 32 bits -> 1 bit

And today's useless piece of trivia is...

You can't have a 1bit variable in C-ish languages. char is guaranteed to be the
smallest variable (8bit). Of course, you can back 8 boolean values into a char
(which is what std::vector<bool> does).

#include <iostream>

int main()
{
        std::size_t const bool_size = sizeof(bool);
        std::size_t const int_size = sizeof(int);
        std::cout << "sizeof(bool) == " << bool_size << '\n'
                  << "sizeof(int)  == " << int_size << std::endl;
        return 0;
}

Testing this out on:
* an x86 box running Windows and compiling with MSVC2005
* an x86 box running Linux and compiling with g++ 4.0.2
* a 64 bit Dec Alpha box running Linux and compiling with g++ 4.0.3

All three produce the output:
sizeof(bool) == 1
sizeof(int)  == 4

Somewhat freakily, I have the distinct memory that sizeof(bool) on a 64 bit Dec
Alpha running tru64 unix and compiling with cxx produced sizeof(bool) == 4.

Angus

Reply via email to