Question

(A case of over relying on an IDE)

I have some legacy C code that I compile as C++ for the purpose of Unit testing. The C source is C++ aware in that it conditionally defines based on environment.

E.g. (PRIVATE resolves to static):

#if!defined __cplusplus
#define PRIVATE1 PRIVATE
#endif

...

PRIVATE1 const int some_var;

The problem is I just can't seem to find out what PRIVATE1 resolves to or is in C++, the compiler complains of redefinition if I add a declaration but doesn't indicate where?

I have searched my MinGW/gcc include path, the C++ ISO specification and the C++ books available to me has been to no avail.

Edit:

Sure I checked the command line and makefiles before posting.

Was it helpful?

Solution 4

Eclipse C++ managed project's are a little, well stupid!

If a project is declared C++ it still bases it's build on file extension, hence .h file preprocessed as C and not C++ header which pulls in a #define PRIVATE1 from another header file similarly wrapped by:

#ifdef __cpluplus.

The project is then linked by g++.

OTHER TIPS

There's nothing like this in ISO C++ spec. Most likely, PRIVATE1 (as well as PRIVATE) are defined elsewhere in the project. Note that this doesn't need to be a #define in an .h file - it can also be defined via compiler switches in the makefile. I'd suggest doing a full grep on the project directory.

If PRIVATE1 resolves to PRIVATE, and PRIVATE resolves to static, then PRIVATE1 resolves to static.

It's unlikely (but not impossible) that they are defined by MinGW itself. Macros defined by the C++ or C implementation should begin with an underscore.

Your best bet is to look at the preprocessor output. You didn't post what compiler you are using, but if you check the docs, most have an option to "Preprocess to file" which will create a file with all the macros substituted. This might be able to help you figure out what is happening. In Visual Studio you use the /E option (under C/C++->Preprocessor->Generate Preprocessed File) which will turn foo.c into foo.i. This file will generally be HUGE compared to the original source file, so scroll down to the bottom to see your code.

Most likely in C++ it's defined to, well, "private:".

Can you declare a function with PRIVATE1? If so, just write a function like so:

PRIVATE1 void Foo() {
    // __FUNCSIG__ in Visual Studio, not sure about GCC
    std::cout << __FUNCSIG__ << std::endl;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top