You might find it reasonable to define three macros to help with this:
#ifdef __cplusplus
#define EXTERN_C_BEGIN extern "C" {
#define EXTERN_C_END }
#define EXTERN_C extern "C"
#else
#define EXTERN_C_BEGIN /* Nothing */
#define EXTERN_C_END /* Nothing */
#define EXTERN_C extern /* Or Nothing */
#endif /* __cplusplus */
This would be most useful in a standard header that's included in most places in your project. For a single function, you might write:
EXTERN_C size_t insert(const char *name);
For a group of functions, you might write:
EXTERN_C_BEGIN
size_t other_insert(const char *name);
size_t other_delete(const char *name);
size_t other_update(const char *old_name, const char *new_name);
EXTERN_C_END
It is permissible to include extern
in front of the individual functions inside the EXTERN_C_BEGIN
to EXTERN_C_END
block.