C++ questions...

Started by
7 comments, last by kmsixpence 22 years, 5 months ago
I've been programming for a little while in c++ and directx and I started noticing some stuff I never noticed before. My question is if the bool type is really a macro. It could be defined somewhere in the windows macros like so:
    
//type bool define

#define BOOL int

#define bool int

#define FALSE 0

#define false 0

#define TRUE 1

#define true 1
    
I'm just curious for anyone who knows, is that how it is? Edited by - kmsixpence on November 4, 2001 6:55:13 PM
Advertisement
The "bool" type is a part of both C and C++. The "true" and "false" types are too. The byte size of bool and the values of true and false aren''t specified. However, BOOL, TRUE, and FALSE are part of the Win32 API (not C or C++). BOOL is a typedef for int, TRUE is 1, and FALSE is 0.

[Resist Windows XP''s Invasive Production Activation Technology!]
Types in all capital letters such as "BOOL" are defines that Microsoft has provided. BOOL is a typedef int, as you suggest. However, 'bool' is an actual C++ datatype such as 'int' and is a part of the language, as is 'true' and 'false' (but not 'TRUE' and 'FALSE' which are defines for 1 and 0, respectively)

Typedefs such as BOOL and TRUE and FALSE are holdovers from C. In C++, you can use bool, true, and false if you prefer but I see lots of C++ programmers using BOOL just because it is consistent with what you have to use when writing plain C.

Edit: Null and Void beat me to it. To my understanding, bool is not a part of ANSI C, however, the standard could have changed from when I first had a C programming class (about 6 years ago).

Edited by - jaxson on November 4, 2001 7:03:12 PM
C++ Draft, 3.9.1.6:
quote:
6 Values of type bool are either true or false.40) [Note: there are no signed, unsigned, short, or
long bool types or values. ] As described below, bool values behave as integral types. Values of type
bool participate in integral promotions (4.5).



"I contend that we are both atheists. I just believe in one fewer god than you do. When you understand why you dismiss all the other possible gods, you will understand why I dismiss yours." - - Stephen Roberts
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
quote:Original post by jaxson
To my understanding, bool is not a part of ANSI C, however, the standard could have changed from when I first had a C programming class (about 6 years ago).

It was added in 1999 (C99 Standard) .

[Resist Windows XP''s Invasive Production Activation Technology!]
Okay, I get it. Thanks
quote:Original post by jaxson

Edit: Null and Void beat me to it. To my understanding, bool is not a part of ANSI C, however, the standard could have changed from when I first had a C programming class (about 6 years ago).

Edited by - jaxson on November 4, 2001 7:03:12 PM


Actuallly, you''re right, bool was never implemented in good old ANSI C compliant compilers. You had to typedef them or #define them. I remember when I first switched from Pascal to C, I tried to define a boolean and the compiler would just blast me with errors until I read that I had to define them myself...



"And that''s the bottom line cause I said so!"

Cyberdrek
Headhunter Soft
A division of DLC Multimedia

Resist Windows XP''s Invasive Production Activation Technology!

"gitty up" -- Kramer
[Cyberdrek | ]
quote:Original post by Cyberdrek
Original post by jaxson

Edit: Null and Void beat me to it. To my understanding, bool is not a part of ANSI C, however, the standard could have changed from when I first had a C programming class (about 6 years ago).

Edited by - jaxson on November 4, 2001 7:03:12 PM


Actuallly, you''re right, bool was never implemented in good old ANSI C compliant compilers back in the Old days. You had to typedef them or #define them. I remember when I first switched from Pascal to C, I tried to define a boolean and the compiler would just blast me with errors until I read that I had to define them myself…

However, my good friend Null And Void is correct, It was added in 1999, I stand corrected…

"And that''s the bottom line cause I said so!"

Cyberdrek
Headhunter Soft
A division of DLC Multimedia

Resist Windows XP''s Invasive Production Activation Technology!

"gitty up" – Kramer



"And that''s the bottom line cause I said so!"

Cyberdrek
Headhunter Soft
A division of DLC Multimedia

Resist Windows XP''s Invasive Production Activation Technology!

"gitty up" – Kramer
[Cyberdrek | ]
The thing is that most leading compilers still don''t implement the C99 standard, which kinda sucks.
==========================================In a team, you either lead, follow or GET OUT OF THE WAY.

This topic is closed to new replies.

Advertisement