www.digitalmars.com         C & C++   DMDScript  

c++ - bool behaviour still char (DM 8.29n)

Source:

#include <stdio.h>

bool flags[sizeof(unsigned long) * 8];

void main()
{
    unsigned long l = 0xffffffffL;

    printf("sizeof(bool) = %d\n", sizeof(bool));

    for (int i = 0; i < sizeof(unsigned long) * 8; i++)
        flags[i] = l & (1 << i);

    for (int i = 0; i < sizeof(unsigned long) * 8; i++)
        printf("%d %d\n", i, flags[i]);
}


Output:

sizeof(bool) = 1
0 1
1 2
2 4
3 8
4 16
5 32
6 64
7 -128
8 0
9 0
10 0
11 0
12 0
13 0
14 0
15 0
16 0
17 0
18 0
19 0
20 0
21 0
22 0
23 0
24 0
25 0
26 0
27 0
28 0
29 0
30 0
31 0
Aug 06 2002