I want to use the <complex.h>
library to speed up some calculations, which may include up to 20 complex elements and operation (+ - * /). However, my colleague has declared a struct:
struct complex {
double a;
double b;
};
Therefore the complex
macro coming from the library cannot be used due to conflict with the above structure.
The thing is, I cannot change the name of the struct due to the vast impact on the current project. I tried using the _Complex
macro instead, and remove the #include <complex.h>
header, it worked but _Imaginary_I
, _Complex_I
or I
does not work.
#include <stdio.h> /* Standard Library of Input and Output */
// #include <complex.h> /* I want to remove this */
int main() {
struct complex
{
double a;
double b;
};
double _Complex z1 = 1.0;// + 3.0 * _Complex_I;
double _Complex z2 = 1.0;// - 4.0 * _Complex_I;
// none of these work
double _Complex z = CMPLX(0.0, -0.0);
double _Complex z3 = 1.0 + 1.0 * _Imaginary_I;
double _Complex z4 = 1.0 + 1.0 * _Complex_I;
double _Complex z5 = 1.0 + 1.0 * I;
printf("Starting values: Z1 = %.2f + %.2fi\n", creal(z1), cimag(z1));
}
I expected a way to distinguish between complex macros coming from the library, and the defined complex structure. Sadly I cannot change the structure, so things got unexpectedly more complicated.
My __STDC_VERSION__
is 201112L
, while __VERSION__
is "4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.46.4)".