Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is the word `false` written blue and the word `FALSE` written purple in Visual Studio?

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?

like image 763
EnvelopedDevil Avatar asked Sep 05 '14 07:09

EnvelopedDevil


People also ask

What is the yellow line in Visual Studio?

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.

Is Visual Studio an IDE or text editor?

Visual Studio: IDE and Code Editor for Software Developers and Teams.

What is code editor in Visual Studio?

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.


2 Answers

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.

like image 132
Sneftel Avatar answered Sep 29 '22 20:09

Sneftel


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.

like image 35
Bathsheba Avatar answered Sep 29 '22 19:09

Bathsheba