diff --git a/include/LightGBM/c_api.h b/include/LightGBM/c_api.h index aaf35fe1c12e..b5542891b063 100644 --- a/include/LightGBM/c_api.h +++ b/include/LightGBM/c_api.h @@ -15,9 +15,16 @@ #include +#ifdef __cplusplus #include #include #include +#else +#include +#include +#include +#include +#endif typedef void* DatasetHandle; /*!< \brief Handle of dataset. */ @@ -79,7 +86,7 @@ LIGHTGBM_C_EXPORT int LGBM_SampleIndices(int32_t num_total_row, void* out, int32_t* out_len); -// --- start Dataset interface +/* --- start Dataset interface */ /*! * \brief Load dataset from file (like LightGBM CLI version does). @@ -424,7 +431,7 @@ LIGHTGBM_C_EXPORT int LGBM_DatasetGetNumFeature(DatasetHandle handle, LIGHTGBM_C_EXPORT int LGBM_DatasetAddFeaturesFrom(DatasetHandle target, DatasetHandle source); -// --- start Booster interfaces +/* --- start Booster interfaces */ /*! * \brief Get boolean representing whether booster is fitting linear trees. @@ -1321,7 +1328,17 @@ LIGHTGBM_C_EXPORT int LGBM_NetworkInitWithFunctions(int num_machines, void* reduce_scatter_ext_fun, void* allgather_ext_fun); -#if defined(_MSC_VER) +#if !defined(__cplusplus) && (!defined(__STDC__) || (__STDC_VERSION__ < 199901L)) +#define INLINE_FUNCTION /*!< \brief inline specifier no-op in C using standards before C99. */ +#else +#define INLINE_FUNCTION inline /*!< \brief Inline specifier. */ +#endif + +#if !defined(__cplusplus) && (!defined(__STDC__) || (__STDC_VERSION__ < 201112L)) +#define THREAD_LOCAL /*!< \brief Thread local specifier no-op in C using standards before C11. */ +#elif !defined(__cplusplus) +#define THREAD_LOCAL _Thread_local /*!< \brief Thread local specifier. */ +#elif defined(_MSC_VER) #define THREAD_LOCAL __declspec(thread) /*!< \brief Thread local specifier. */ #else #define THREAD_LOCAL thread_local /*!< \brief Thread local specifier. */ @@ -1340,9 +1357,9 @@ static char* LastErrorMsg() { static THREAD_LOCAL char err_msg[512] = "Everythin * \brief Set string message of the last error. * \param msg Error message */ -inline void LGBM_SetLastError(const char* msg) { +INLINE_FUNCTION void LGBM_SetLastError(const char* msg) { const int err_buf_len = 512; snprintf(LastErrorMsg(), err_buf_len, "%s", msg); } -#endif // LIGHTGBM_C_API_H_ +#endif /* LIGHTGBM_C_API_H_ */