true vs. TRUE and false vs. FALSE

So I've heard that true doesn't work while setting boolean values and that I must use TRUE. I've tested this in the following program:
1
2
3
4
5
6
7
#include <genlib.h>

main()
{
      bool test=TRUE; 
      system ("PAUSE"); 
}

Now, this works with both TRUE and true, but true, TRUE, false, and FALSE are all absent in the list of "names of variables that are not permitted". This confuses me. Any explanation(s) would be highly appreciated!
setting boolean values uses true or false, TRUE and FALSE are incorrect unless you have them declared in other librarys. For example, in SFML you either use return EXIT_SUCCESS or return EXIT_FAILURE instead of 1 or 0. This is because they are decalred in the SFML library, genlib.h must hold the TRUE and FALSE values.
I don't know what TRUE and FALSE are. I guess they are some non-standard macros.

Is this C or C++?

In C++ true and false are keywords and you can't have variables with that name.

C doesn't have bool but C99 has _Bool. If you include stdbool.h in C99 you can use bool, true and false similar to how they are used in C++. The difference in stdbool.h they are macros. bool is defined as _Bool, true as 1 and false as 0.

Need4Sleep wrote:
For example, in SFML you either use return EXIT_SUCCESS or return EXIT_FAILURE instead of 1 or 0. This is because they are decalred in the SFML library

EXIT_SUCCESS and EXIT_FAILURE are defined in cstdlib.
Last edited on
Second result on google for genlib gives me this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#ifdef THINK_C
   typedef int bool;
#else
#  ifdef TRUE
#    ifndef bool
#      define bool int
#    endif
#  else
#    ifdef bool
#      define FALSE 0
#      define TRUE 1
#    else
       typedef enum {FALSE, TRUE} bool;
#    endif
#  endif
#endif 


Looks like just a way to get bools into C.
If you are thinking about Windows, the Windows SDK defines its own boolean type and values:

1
2
3
typedef int BOOL;
#define TRUE 1
#define FALSE 0 


This was done because the Windows API is C, meaning no boolean data type existed.
1
2
@Peter87 
C doesn't have bool but C99 has _Bool. 


You are wrong. _Bool in C is not a bool type. It is unsigned integral type which takes two values 0 and 1.
I don't see how that makes me wrong.
It means that no C no C99 has bool type. C in whole has no bool type. It has now only one additional unsigned integral type. It is the difference between C and C++.
In C the value of expression for example x > y is always integral type and has the result value either 0 or 1 (even before C99) . So the C99 Standard only added one more unsigned integral type with stortened domain.
Last edited on
If not for the first three words, I'd say he's just agreeing with you.
Topic archived. No new replies allowed.