Hallo. I want to use the ISO C99 complex datatypes in c++ because they are faster than the template complex types from std++. g++ fails to work with ISO C99 complex in the following way: typedefs+built-in-functions(conj)+unary minus are not working well together. >>>>cat test.cpp #include </usr/include/complex.h> typedef complex double zcomplex; int main() { zcomplex f=1+_Complex_I*1; f=-_Complex_I; f=conj(f); return 0; } >>>>g++ -Wall test.cpp test.cpp: In function `int main()': test.cpp:9: error: wrong type argument to unary minus test.cpp:11: error: wrong type argument to conjugation >>>>g++ -v Reading specs from /usr/lib/gcc-lib/i586-suse-linux/3.3.4/specs Configured with: ../configure --enable-threads=posix --prefix=/usr --with-local-prefix=/usr/local --infodir=/usr/share/info --mandir=/usr/share/man --enable-languages=c,c++,f77,objc,java,ada --disable-checking --libdir=/usr/lib --enable-libgcj --with-gxx-include-dir=/usr/include/g++ --with-slibdir=/lib --with-system-zlib --enable-shared --enable-__cxa_atexit i586-suse-linux Thread model: posix gcc version 3.3.4 (pre 3.3.5 20040809) gcc compiles the c-version without problems. g++-versions 3.3.4,3.4.3(mingw),3.1.x,... are broken.
"I want to use the ISO C99 complex datatypes in c++ because they are faster than the template complex types from std++." Why do you say that? Well maybe before 4.0.0 it was slower but only slightly.
Confirmed. However, this has really low priority: the C++ standard is not a superset of the C99 standard, so a number of things new to C99 are not part of C++, and this is one of them. If you want to write portable code, you should use the std::complex class. If you have cases where you can show that std::complex is slower than using the C99 means, we'd be happy to accept bug reports. Thanks Wolfgang
(In reply to comment #2) > Confirmed. However, this has really low priority: the C++ standard is not > a superset of the C99 standard, so a number of things new to C99 are not > part of C++, and this is one of them. If you want to write portable code, > you should use the std::complex class. If you have cases where you can show > that std::complex is slower than using the C99 means, we'd be happy to > accept bug reports. > > Thanks > Wolfgang Note this bug, which you considered as low priority since it applied to using C code with the C++ compiler, is not limited to the C++ compiler. Take a look at #42753 where you will see this bug stops one building C code if using gcc.
FWIW, this has been fixed for 4.5.x.
Created attachment 38343 [details] stack misalignment using complex<double> #include <complex> #include <iostream> //changes typedef std::complex<double> Cx; Cx foo(int kojack) { double x=3, y=kojack; return (x, y); } int main(int argc, char *argv[]) { Cx z1(3.0, 4.0); Cx z2(foo(4)); std::cout << "z1=" << z1 << std::endl; std::cout << "z2=" << z2 << std::endl; // compiled with gcc 4.8.4 on lxle // g++ -o bug bug.cpp //output: //z1=(3,4) //z2=(4,0) } ////////////end