I have a couple of files written in C, and I want them to be C++-compatible, so for my C headers I use;
#ifdef __cplusplus
extern "C" {
#endif
at the beginning of the file and of course
#ifdef __cplusplus
}
#endif
...at the end. But it seems to create problems with the 'inline' keyword. My solution is to simply remove the inline keyword for C++, but I guess it could have a bad effect on C++ programs (these functions are called gazillions of times).
Is there a better solution ?
If I understand correctly, I would do:
#ifdef __cplusplus
#define D_INLINE static
extern "C" {
#else
#define D_INLINE inline
#endif
And use the D_INLINE for the functions that I think should need inline. As delnan said, the compiler will optimize it anyway and the inline keyword is just a hint to the compiler that the programmer thinks that the compiler should inline the function. It doesn't force the compiler to inline the function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With