One of the multiple features of vscode is that when using C or C++ code and we have
#ifdef SOMETHING
this
and this
#endif
if SOMETHING is not defined the code appears shadowed.
That is fine and dandy. I know you can set that in the time of building (so my question is not that) but I want to read the code as if SOMETHING is defined.
So my question is how can I make VSCode assume that that SOMETHING is defined?
right now I am just putting a comment on the #ifdef but I don't think that is a suitable way of doing this
To start, open the c_cpp_properties.json file for your workspace. This should be in the .vscode folder. If the file doesn't exist, you can create it by opening the command palette with ctrl+shift+p and entering the command C/C++: Edit Configurations (JSON).
Next, add any preprocessor defines to the defines array:
{
"configurations": [
{
"defines": [
...
"YOUR_DEFINE_HERE"
],
...
}
],
...
}
Now, VScode will treat your value(s) as defined and shadow/highlight code appropriately for all C/C++ files in the directory.
You can also add multiple configurations to the c_cpp_properties.json file with different sets of defines. To switch the active configuration, open the command palette and enter C/C++: Select a Configuration.... This is useful for switching between debug and release configurations that may have different sets of defines.
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