This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: C++ name mangling in C



Cytowanie Marc Glisse <marc.glisse@inria.fr>:

Therefore I was looking for a way to detect such bugs with some tool. I thought about forcing C++ mangling when compiling C code, but looks that gcc does not have any command line option to this. Please correct me if I am wrong.

If there is no such option, I would like to open an enhancement to add it. I thought about it for some time and looks that this new option should do 3 things: enable C++ name mangling, enable extern "C" directive and define the __cplusplus macro. Any comments on this proposal is also welcome.

How about compiling your code with g++ then? (possibly add -fpermissive to accept more C-isms)

I already tried, and got error on some typedef struct declaration (do not remember exact syntax now). I will try to add -fpermissive and see if it will help.

If you define __cplusplus, you'll need a C++ compiler anyway because the headers will contain C++ code.

I see. In my case this is needed mostly for C stdlib. Other 3rd party libs usually have C and C++ interface separated, so simple support for extern "C" would be enough.

Another option to use instead of defining __cplusplus is to generate C names for functions defined in system headers (including ones from paths specified with -isystem). But this seems to be more complex, probably some extra interaction between preprocessor and compiler would be needed.

Compiling with -flto may also generate interesting messages.

Will give it a try too.

--
Regards,
Daniel


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]