This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
C99 _Complex and C++ complex<> interoperability.
- From: "Smith-Rowland, Edward M" <ESmith-rowland at alionscience dot com>
- To: <libstdc++ at gcc dot gnu dot org>
- Date: Thu, 22 Feb 2007 13:25:02 -0500
- Subject: C99 _Complex and C++ complex<> interoperability.
All,
This message is probably a combination of C++ standards (OT), gcc
implementation, and gcc-help so apologies in advance.
In discussions on the GSL mailing list about special functions and other
numerical issues, complaints about the lack of interoperability of C++
complex and C99 complex came up. I'm trying to hunt down information on
these issues.
I have noticed that it is possible (since 4.0) to construct and assign
from a C99 complex number to a C++ complex number.
I think this is very cool. This goes part way towards reconciling C99
and C++ as far as complex numbers are concerned.
I don't see this in the C++ standard or under g++ extensions in the
manual.
My questions are:
Is this behavior standard or is this a gcc extension?
If this is a gcc extension where is it documented?
Also, if this behavior is nonstandard is anyone thinking about
standardizing it?
Finally, the circle would be complete if we could assign from
std::complex to _Complex.
Any ideas? There is a private functions that return _Complex from
std::complex.
Being able to have a nonmember assignment operator would really nail it.
Thank you.
This thing compiles:
----------------------------------------------------------
#include <complex>
int main(int, char**)
{
std::complex<float> jf(0.0F, 1.0F);
std::complex<double> jd(0.0, 1.0);
std::complex<long double> jl(0.0L, 1.0L);
float _Complex jcf;
double __complex__ jcd;
long double _Complex jcl;
std::complex<float> zff(jcf);
std::complex<float> zfd(jcd);
std::complex<float> zfl(jcl);
std::complex<double> zdf(jcf);
std::complex<double> zdd(jcd);
std::complex<double> zdl(jcl);
std::complex<long double> zlf(jcf);
std::complex<long double> zld(jcd);
std::complex<long double> zll(jcl);
std::complex<float> wff = jcf;
std::complex<float> wfd = jcd;
std::complex<float> wfl = jcl;
std::complex<double> wdf = jcf;
std::complex<double> wdd = jcd;
std::complex<double> wdl = jcl;
std::complex<long double> wlf = jcf;
std::complex<long double> wld = jcd;
std::complex<long double> wll = jcl;
//jcd = jd; // Fails.
// Try some arithmetic.
//std::complex<double> a = jcd + jd; // Fails.
//std::complex<double> b = jd + jcd; // Fails.
return 0;
}