C ++ and <complex.h> with <complex> in separate files

Notes:

I am compiling on OSX using Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)

In particular, I'm trying to compile a monolithic source from LibIIR, a filter library supported by Laurence Withers here .

I already looked at this answer here about using both <complex>, and <complex.h>in the same file.


Setup:

I have a file iir.h, for example:

#include <complex.h>

#ifdef __cplusplus
extern "C" {
#endif

...

I have C ++ source and header files libiir++.cppand iir++.has follows:

/*** libiir++.cpp ***/
// we need to include "iir.h" first, as it pulls in <complex.h>, which we need
// to take effect before "iir++.h" pulls in <complex>
#include "iir.h"

// now remove the preprocessor definition of complex to _Complex, which is fine
// for the C header but not good for the C++ header
#undef complex

#include "iir++.h"

namespace IIR {

...

-

/*** iir++.h ***/
#include <complex>

namespace IIR {

...

Problem:

clang gives me the following compilation error:

./iir.h:570:15: error: expected ';' after top level declarator
double complex iir_response_c(const struct iir_coeff_t* coeff, double freq);
              ^
              ;

, <complex> - #undef complex - , . , ?

+1
1

<complex.h> C ++.

++ C , <c***>. , ++ <complex.h> <ccomplex>. ++:

<ccomplex>

, <complex>.

C, ++.

: C ++. __cplusplus.

,

#if __cplusplus
#   include <complex>
    typedef std::complex< double > cdouble;
#else
#   include <complex.h>
    typedef double complex cdouble;
#endif

. std::complex< double > double complex ++ 14 [complex.numbers] §26.4/4 C11 §6.2.5/13. , cdouble , , , ABI.


, ++ , , #include <complex.h>, :

C, name.h, , , cname, . , (3.3.6) std - (7.3.3).

, #include <complex.h> ::complex<T>. .

+3

Source: https://habr.com/ru/post/1677489/


All Articles