In C99, it looks like the '~' operator on a _Complex performs a complex conjugate. The following code:
#include <complex.h>
#include <stdio.h>
int main()
{
double _Complex a = 2 + 3 * I;
printf("%f,%f\n", creal(~a), cimag(~a));
}
Gives the output:
2.000000,-3.000000
This behaves the same in both gcc and clang. Is this an extension? I can't seem to find any reference to it in the various standards documents google pulled up.
If it is an extension, is there a way to deactivate it?
This is in fact a gcc extension, documented in section 6.11 of the gcc manual:
The operator
~
performs complex conjugation when used on a value with a complex type. This is a GNU extension; for values of floating type, you should use the ISO C99 functionsconjf
,conj
andconjl
, declared in<complex.h>
and also provided as built-in functions by GCC.
If you compile with the -pedantic
flag, you'll get a warning for this:
x1.c: In function ‘main’:
x1.c:6:29: warning: ISO C does not support ‘~’ for complex conjugation [-Wpedantic]
printf("%f,%f\n", creal(~a), cimag(~a));
^
x1.c:6:40: warning: ISO C does not support ‘~’ for complex conjugation [-Wpedantic]
printf("%f,%f\n", creal(~a), cimag(~a));
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