Why does Visual Studio change the word color depending on the way it is entered:
false
with blue, but FALSE
with purple.true
with blue but TRUE
with purple.
Is there any difference in the meaning of them and if yes what is it?
Yellow: The line has been changed but not yet saved. Green: The line has been changed and saved. Orange: The line has been changed, saved, and the change undone.
Visual Studio: IDE and Code Editor for Software Developers and Teams.
The Visual Studio editor provides many features that make it easier for you to write and manage your code and text. You can expand and collapse different blocks of code by using outlining. You can learn more about the code by using IntelliSense, the Object Browser, and the Call Hierarchy.
false
is a keyword in C++; it's blue for the same reason for
is blue. FALSE
is a preprocessor macro declared by the Windows API; it's purple for the same reason MYFILE_H_DEFINED
is purple. If you go into the editor preferences for C++, you'll see the colors MSVC is using for different identifiers.
Incidentally, TRUE and FALSE are WinAPI-specific and are a throwback to C, and should not be used except when communicating with the WinAPI.
true
and false
are keywords in C++ so your IDE (not the compiler) is painting them blue.
TRUE and FALSE are often defined by various headers, primarily for compatibility with C and older C++ compilers where true
and false
are not keywords.
As for their equivalence, the C++ standard does not define sizeof(true)
and sizeof(false)
to be 1 but they will be the same as sizeof(bool)
. Footnote 69 for C++ standard:
sizeof(bool) is not required to be 1.
You'll probably find that sizeof(TRUE)
and sizeof(FALSE)
are sizeof(int)
since TRUE and FALSE are often defined as int
types, but it would be unwise to assume this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With