Complex type with C-binding in C ++ 11

I need to include the C library header in my C ++ 11 code. Now the header provides procedures and data structures that include many double complexeverywhere. For example.

#include <complex.h>
//..
typedef struct parameters
{
    // ...
    double complex Vud;
} parameters;
// ...
double complex polylog(int n, int m, double x);

I bring this file to my C ++ 11 source code wrapped in extern "C" { #include "include.h" }(this is the actual file name, believe it or not). And g ++ (tried 4.7.3 and 4.8.2), and clang (3.3) go nuts, if I added -std = C ++ 11.

There are many millions of g ++ error strings:

include/g++-v4/cmath:98:3: error: template with C linkage

And clang gives:

cmath:84:3: error: declaration conflicts with target of using declaration already in scope
  abs(double __x)
  ^
/usr/include/stdlib.h:773:12: note: target of using declaration
extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
           ^
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/cstdlib:245:14: note: using declaration
  using std::abs;
             ^

I am not sure how to get around this. What is the right way to do this? Obviously, they should be interchangeable, but I don't know the trick.

+5
source share
1 answer

100% ++ extern "C". include.h ++-friendly, extern "C", extern "C".

17.6.2.2 [using.headers]

[...]

3 , .

extern "C" {
#include <complex.h>
}

, . , , <complex.h>.

, include.h , , include.h . , , no-op, , include.h , .

+7

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


All Articles