When you use g++, __cplusplus will be defined automaticly.(you can’t
undef it in fact.) When you use gcc, __cplusplus is not defined. At the
same time, When you g++ a.c file, although file extension is .c, but
gcc still use name mangling to change function name. (The conclusion
is based on g++ and gcc in lunux system)
If you have c and cpp source file together, you can just use g++ compile
them all. You don’t need any __cplusplus syntax. g++ compile all
files using name mangling. (look them as c++ files). At this time file
extension doesn’t play a role at all.
If you c++ file want to use a c function. You don’t have c function source
code(It is in a lib) or you don’t want to recompile it( it’s very big files). At
this time, you should use it in head file or function declaration.
If you define a function in a.cpp file(You have to use g++ to compile it),
and this function will be used in legacy C system, you need the previous
trick again. give lib and head file to C system, and then the C system can
include head file and linked to lib.
In one word, if you have obj code produced by C or C++, Whenyou want to linked it to you current project, maybe you shouldconsider using "__cplusplus"