I want to have some code only be included when Eclipse is parsing my source tree. At the moment, what I am doing^H^H^H^H^H trying to do is add a custom preprocessor macro - using Eclipse's Help | Preferences | C/C++ | Build | Setting Discovery - and insert a -DECLIPSE_BUILTIN
into the various command-lines there.
So I was wondering whether there is already a standard, a default, macro which the preprocessor (and the indexer?) define to 'identify' themselves like this to the code - to save me the trouble.
Yes, such a macro exists. It's __CDT_PARSER__
.
Source
EDIT to clarify when this is used in the context of showing error and warning indicators:
CDT obtains error and warning indicators from two sources:
It can parse the output of your build, recognize errors and warnings in that output, and surface those in the editor.
These error and warning indicators have the annotation types Errors
and Warnings
(you can see the different annotation types, including the icons for each type, in in Preferences | General | Editors | Text Editors | Annotations
).
The build whose output is parsed for this purpose is the same build that produces your object files (and these indicators are only updated when you invoke a build, such as via Project | Build Project
). As such, __CDT_PARSER__
is not used for this build.
It can analyze your code using its own parser, and point out errors and warnings that it spots. This is independent of your compiler, and happens as you type.
This produces error and warning indicators with the annotation types Codan Errors
and Codan Warnings
("codan", short for code analysis, being the component that produces these). There is also C/C++ Indexer Markers
for syntax errors, which are produced during the parsing itself.
This, naturally, does use __CDT_PARSER__
.
Note that CDT's code analysis does not catch all of the errors (or warnings) that your compiler does. There is also the possibility of it producing false positive errors or warnings, which can often happen due to an indexer configuration that doesn't match the build configuration, but sometimes also happens due to bugs or deficiencies in CDT itself.
EDIT To further clarify, the indexer uses the same parser as codan (with __CDT_PARSER__
being defined and all) to build the index. (In fact, the indexer and the parser are not really separable, since the parser relies on the index to resolve names defined in included header files during parsing.)
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