Problem Description
-
When using VS Code to view Linux code or RT-Thread code, it is often encountered that a certain C language macro definition is configured in the project, but VS Code cannot recognize it, causing the code to be displayed in gray by default. When reading the code, analyzing the code flow causes confusion
-
This problem generally does not exist in small projects. In some copied code projects, there are some global macro definitions, which may not be defined, such as those specified in the compilation tool chain, so this part of the code is grayed out when read.
Manually define macro definitions
-
Here you need to install the VS Code C/C++ plug-in. After installation, you can add the macro definition you want to define in the plug-in JSON configuration file.
-
For example, if I want to open it in RT-Thread code
RT_USING_MEMHEAP
, the operation steps are as follows: -
Click the F1 shortcut key, enter in the search bar
c/c++
, find it in the drop-down list, there is one hereC/C++:Edit Configurations (JSON)
, click to open.vscode\c_cpp_properties.json
- Add
"defines"
it manually"RT_USING_MEMHEAP",
, then save it, and look at the code again, and find that the C language macro has taken effect.
"defines": [
"_DEBUG",
"UNICODE",
"RT_USING_MEMHEAP",
"_UNICODE"
],
summary
-
The code editing and reading functions of VS Code are relatively powerful. With various plug-ins, the functions are more convenient to use and make code development more efficient
-
You can try to add the macro definition you want to define to make the code easier to read.