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.)
#define MY_MACRO value
, which would look like-DMACRO=value
if passed as a command-line argument togcc
org++
, by following my detailed instructions here: How can I convince Eclipse CDT that a macro is defined for source code editing and code completion?. This is really useful to "guide" the Eclipse indexer to index things properly without having to change your source code to use__CDT_PARSER__
. – Koffman