"Pedro Izecksohn" <[EMAIL PROTECTED]> wrote: > > If any value not zero is true why "true which expands to the > integer constant 1"?
How can a macro expand to multiple values? That's the problem. Note that C is not the only language with the difficulty. In Pascal (IIRC) and many Basics, it's the least significant bit that determines the true/false status. So for example, zero was false, 1 was true, 2 was false, 3 was true, etc... The issue is that the true macro is not for use as a conditional test itself. If compared at all, it is best compared to a boolean object, or a relational, equality or logical expression. > I wasted a week to find a bug that I wrote like: > > if ((x&y)==true) //etc I imagine you did, however similar code is likely to be a bug in many other weakly types languages for the same reason it's a bug in C. 'Equals true' is just not the same as 'is true'. > but I should have written just: > > if (x&y) //etc Or... if ((x & y) != 0) > "The remaining three macros are suitable for use in #if > preprocessing directives." The section refers to the macros: true false __bool_true_false_are_defined 'Suitable for use' refers to the fact that they can be used in preprocessing directives. Not every macro can. For instance the following cannot... #define MY_SIZE_MAX ((size_t)-1) A directive like... #if MY_SIZE_MAX > 65535 ...will likely fail to compile because preprocessing directives do not understand integer types or type names. > Could you point to some real example? 'bool' is a built in type in C++, but it was not in C90. Because it was a useful thing to define, many programs and libraries did define their own version of booleans. It's for that reason that C99 added _Bool, not bool, into the language as a keyword, and opted for the <stdbool.h> header. Updating programs to C99 may require a careful step to avoid duplicating bool with existing user definitions. So if you're using bool, you might do something like... #include some_library_header #if !__bool_true_false_are_defined #include <stdbool.h> #endif If you include <stdbool.h> unconditionally, you may encounter compilation problems if the macros true and false, or the typedef bool are already defined outside of <stdbool.h>. -- Peter
