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.
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.