[PLUGINS] Add 'extern "C"' wrappers to several header files

Rafael Espindola espindola@google.com
Wed Jul 22 10:27:00 GMT 2009


2009/7/21 Duncan Sands <baldrick@free.fr>:
> I am writing a gcc plugin in C++.  In order to use gcc's functions
> and objects from C++, they need to be declared as having C linkage.
> The attached patch wraps the body of various gcc header files with
>  #ifdef __cplusplus
>  extern "C" {
>  #endif /* __cplusplus */
>  ...
>  #ifdef __cplusplus
>  }
>  #endif /* __cplusplus */
> I made no attempt to do this systematically: these are the headers
> I needed to modify for my plugin to link.  At first sight it might
> appear that there is no need to modify gcc, since the plugin can
> include header files like this:
>  extern "C" {
>  #include "flags.h"
>  }
> But in fact it cannot: some gcc header files include C++ aware
> system headers.  For example, flags.h includes real.h, and real.h
> includes gmp.h, and gmp.h includes C++ system headers if compiled
> from C++.  The result is that if I wrap the inclusion of flags.h in
> an 'extern "C"' wrapper then C++ code ends up with C linkage, and
> compilation fails (templates particularly don't like having C linkage).

I think the patch is OK, but I cannot approve it. Iant might also have
an opinion about it.

Cheers,
-- 
Rafael Avila de Espindola

Google | Gordon House | Barrow Street | Dublin 4 | Ireland
Registered in Dublin, Ireland | Registration Number: 368047



More information about the Gcc-patches mailing list