Archived

This topic is now archived and is closed to further replies.

kmsixpence

C++ questions...

Recommended Posts

kmsixpence    134
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

Share this post


Link to post
Share on other sites
Null and Void    1088
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!]

Share this post


Link to post
Share on other sites
jaxson    127
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

Share this post


Link to post
Share on other sites
Arild Fines    968
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

Share this post


Link to post
Share on other sites
Cyberdrek    100
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

Share this post


Link to post
Share on other sites
Cyberdrek    100
quote:
Original post by Cyberdrek
[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 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

Share this post


Link to post
Share on other sites