From 19b13ea34a35fd9441316b77489effa0d4ebe269 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=BCtzel?= Date: Tue, 4 Jul 2023 17:00:59 +0200 Subject: [PATCH] CXSparse: Avoid including C header in C++ code According to [1]: "Source files that are not intended to also be valid ISO C should not use any of the C headers." It is still correct to define `cs_complex_t` as `double _Complex` in C and C++ code. But the C standard header `complex.h` shouldn't be included in a header that can be used in C++ code. That is not a requirement. But it is a recommendation. Additionally, avoid inclusion of headers inside an `extern "C"` block. [1]: https://en.cppreference.com/w/cpp/standard_library --- CXSparse/Config/cs.h.in | 16 ++++++++++------ CXSparse/Include/cs.h | 16 ++++++++++------ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/CXSparse/Config/cs.h.in b/CXSparse/Config/cs.h.in index e73488a3d..6280e7467 100644 --- a/CXSparse/Config/cs.h.in +++ b/CXSparse/Config/cs.h.in @@ -27,12 +27,12 @@ #define _CXS_H #if @CXSPARSE_USE_COMPLEX@ -#include -#define cs_complex_t double _Complex -#endif - -#ifdef __cplusplus -extern "C" { +# ifdef __cplusplus +# include +# else +# include +# endif +# define cs_complex_t double _Complex #endif #define CS_VER @CXSPARSE_VERSION_MAJOR@ /* CXSparse Version */ @@ -47,6 +47,10 @@ extern "C" { #define cs_long_t_id "%" PRId64 #define cs_long_t_max INT64_MAX +#ifdef __cplusplus +extern "C" { +#endif + /* -------------------------------------------------------------------------- */ /* double/int32_t version of CXSparse */ /* -------------------------------------------------------------------------- */ diff --git a/CXSparse/Include/cs.h b/CXSparse/Include/cs.h index 5a083f82c..e1cf17f04 100644 --- a/CXSparse/Include/cs.h +++ b/CXSparse/Include/cs.h @@ -27,12 +27,12 @@ #define _CXS_H #if 1 -#include -#define cs_complex_t double _Complex -#endif - -#ifdef __cplusplus -extern "C" { +# ifdef __cplusplus +# include +# else +# include +# endif +# define cs_complex_t double _Complex #endif #define CS_VER 4 /* CXSparse Version */ @@ -47,6 +47,10 @@ extern "C" { #define cs_long_t_id "%" PRId64 #define cs_long_t_max INT64_MAX +#ifdef __cplusplus +extern "C" { +#endif + /* -------------------------------------------------------------------------- */ /* double/int32_t version of CXSparse */ /* -------------------------------------------------------------------------- */