Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why BOOL in Windows is of type int?

Tags:

c

windows

winapi

Why not defining BOOL as an enum like in :

enum BOOL {FALSE, TRUE};

Is there any reason why BOOL must be specified explicitly as int (or any other integral type)?

like image 992
Bite Bytes Avatar asked Jan 22 '26 12:01

Bite Bytes


1 Answers

From Raymond Chen's blog article on this topic:

BOOL vs. VARIANT_BOOL vs. BOOLEAN vs. bool

Still more ways of saying the same thing. Why so many?

Because each was invented by different people at different times to solve different problems.

BOOL is the oldest one. Its definition is simply

typedef int BOOL;

The C programming language uses "int" as its boolean type, and Windows 1.0 was written back when C was the cool language for systems programming.

The vast majority of the Win32 API is still designed for C to this day, so that it is compatible with a large variety of programming languages that are compatible with C.

Enums have portability issues across compilers, related to differences in byte size and bit representation. Besides, enum wasn't added to C until ANSI C in 1989 (aka C98), which was after three releases of Windows (1.0 in 1985, 2.0 in 1987, and 2.1 in 1988), and enums are effectively equivalent to integers anyway.

like image 149
Remy Lebeau Avatar answered Jan 24 '26 06:01

Remy Lebeau