As the title says:
How to identify the language type: C or C++ using a preprocessor?
I am making a resource file. Call ids.h
that I plan to use in programs for both C and C++. The idea is that if it's C a structure is compiled, but if it's C++ a class is compiled:
#ifdef _C_
typedef struct{/***@param Code*/}Cadena;
#elif _CPP_
class Cadena{
/**@param Code*/
};
#endif
The objective is to identify the language so that errors do not occur when executing it.
If you're compiling to c++ , the macro
__cplusplus
will be defined, containing the compiler's supported C++ standard number:199711L
before C++11.201103L
C++11.201402L
C++14.201703L
C++17.202002L
C++20.This not only lets you know if you're compiling to C++, it also allows you to make decisions based on the standard used.