Re: C++ and C99 complex
"P.J. Plauger" wrote:
"skaller" <skaller@users.sourceforge.net> wrote in message
news:pan.2006.08.11.01.33.34.253488@users.sf.net...
Can someone explain the current and proposed relationship
between C++ complex library type and C99 complex types?
Its very unsatisfactory to have two distinct types for
complex numbers. C++ complex is a template, and thus a class
type. C99 complex may be a primitive type.
It may be unsatisfactory, but that's the way the two languages
evolved.
If we wanted to make complex<double> the same type as C99
double _Complex, it would seem we'd need to allow a typedef
as a specialisation, eg:
typedef double _Complex
template<> complex<double>;
[unreadable .. I would write:
typedef template<> complex<double> =
double _Complex;
if I could.] Is there another way? Is this possible?
Any help here appreciated, including suggestions how to
handle the dichotomy (apart from the obvious: convert one to
the other as required)
We ensure that the two types have the same representation and are
freely interchangeable in C++.
When you say we, do you mean, "we, the members of the
standardization committee", or "we, the implementors at
Dinkumware"? (I know at one point there was a suggestion to
constraint the implementation of complex<T>, so that it would be
required to be physically equivalent of T[2]. I don't know what
became of it, though.)
That seems to solve most problems that occur when people call
C99 complex functions with C++ complex objects.
I presume that it does mean that you'd need something like:
#ifdef __cplusplus
extern "C" void f( std::complex< double > ) ;
#else
extern void f( double _Complex ) ;
#endif
in your header files, or... ?
And of course, it would be preferable if said header file didn't
include the C header <complex.h>, although that would be the
natural thing for it to do if it were written by the developers
of f() (who are working in C).
--
James Kanze GABI Software
Conseils en informatique orient9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S9mard, 78210 St.-Cyr-l'cole, France, +33 (0)1 30 23 00 34
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]