C ++: external and built-in functions

I have several files written in C and I want them to be compatible with C ++, so for my C headers I use;

#ifdef __cplusplus
extern "C" {
#endif

at the beginning of the file and of course

#ifdef __cplusplus
}
#endif

... in the end. But this creates problems with the keyword "inline". My solution is to simply remove the inline keyword for C ++, but I assume that this may have a bad effect for C ++ programs (these functions are called gazillions times).

Is there a better solution?

+5
source share
2 answers

If I understood correctly, I would do:


 #ifdef __cplusplus
 #define D_INLINE static
 extern "C" {
 #else
 #define D_INLINE inline
 #endif

D_INLINE , , , . , , inline - , , . .

+2

, , :

#ifdef __cplusplus
extern "C" {
#elif __STDC_VERSION__ >= 199901L
   /* do nothing, C99 supports inline */
#else
#  define inline static
#endif

C , __attribute__((always_inline)) ( __GNUC__ )

: .: http://www.greenend.org.uk/rjk/2003/03/inline.html

-2

All Articles