C++ indexer problem


#1

The indexer in M2M studio, seems to have trouble with the following syntax:

#ifdef __cplusplus
extern          "C" {
#endif

// C specific declarations

#ifdef __cplusplus
}
#endif

The indexer reports a syntax error for the extern “C” line, which causes everything until the closing brace to by highlighted with a yellow squiggle.


#2

I guess you are using this “snippet” in “.c” file, isn’t it?
Actually, .c files are assumed to be compiled by the C compiler, so the indexer warns about syntax error…
Using the same snippet in a .h or .cpp file doesn’t cause any syntax error.

From there, it’s true that this snippet doesn’t cause any compilation error, but please can you tell what’s the use of it in a .c file?


#3

This snippet comes from a header (.h) file, not a source file.

If the indexer is assuming that the file is to be compiled with the C compiler rather than the C++ compiler (which would be correct in this case, as the header in #included from a .c file), then it shouldn’t be defining the __cplusplus macro. If the macro wasn’t defined, then the offending code would be ignored.


#4

Correct, we have a bug in defined symbols detection: __cplusplus is defined in C (impacts only the indexer behavior)
Logged for fix in next release
Thanks for your feedback


#5

Could you clarify that?

Do you mean that only the indexer is defining __cplusplus in ‘C’ files?

If the build tools are defining __cplusplus in the actual compilation of ‘C’ files, that could lead to trouble…


#6

Yes, the indexer “believes” that __cplusplus is defined in C files.
But the compiler behaves correctly and doesn’t define it.