I want to call a C function of a complex argument, declared as
double _Complex cerf ( double _Complex z );
from C++. The following works:
#include<complex.h>
double _Complex z = 1.0;
cerf( z );
However, I fail to assign an imaginary part to z:
double _Complex z = 1.0 + _Complex_I * 2.0;
does not compile under g++: "unable to find numeric literal operator ‘operator""iF’". Other expressions I tried lead to other, similarly cryptic error messages.
C++ and C is not completely compatible with each other, especially for C99 features, which may or may not present in C++, and complex number is one of them. C++ and C compatibility
If you are using GCC, you can use the flag -fext-numeric-literals to enable support for _Complex.
Working example
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With