C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

C++ and C99 complex

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards
View previous topic :: View next topic  
Author Message
skaller
Guest





PostPosted: Fri Aug 11, 2006 7:06 pm    Post subject: C++ and C99 complex Reply with quote



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.

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)

--
John Skaller <skaller at users dot sf dot net>
Try Felix, the successor to C++ http://felix.sf.net


---
[ 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 ]
Back to top
P.J. Plauger
Guest





PostPosted: Sun Aug 13, 2006 1:37 am    Post subject: Re: C++ and C99 complex Reply with quote



"skaller" <skaller (AT) users (DOT) sourceforge.net> wrote in message
news:pan.2006.08.11.01.33.34.253488 (AT) users (DOT) sf.net...

Quote:
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.

Quote:
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++. That seems to solve most problems
that occur when people call C99 complex functions with C++
complex objects.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com


---
[ 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 ]
Back to top
skaller
Guest





PostPosted: Tue Aug 15, 2006 7:03 pm    Post subject: Re: C++ and C99 complex Reply with quote



On Sat, 12 Aug 2006 20:37:52 +0000, P.J. Plauger wrote:

Quote:
"skaller" <skaller (AT) users (DOT) sourceforge.net> wrote in message
news:pan.2006.08.11.01.33.34.253488 (AT) users (DOT) sf.net...

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.

Well yes, I know that: different timing of the Standards
and perhaps a failure of liaison.

Quote:
We ensure that the two types have the same representation and are
freely interchangeable in C++. That seems to solve most problems
that occur when people call C99 complex functions with C++
complex objects.

I presume by 'we' you mean Dinkumware .. I guess I'm really
asking if there is any proposal to do anything about it
in the Standards committee .. (er.. used to call that the
ANSI/ISO committee but it isn't ANSI anymore .. whats
the right name for the 'committee as a whole' now?]

My vague proposal for allowing a 'typedef to be a specialisation'
was a suggestion that it might be possible to provide
proper machinery to actually identify the types (in the
case of a C++ library that actually does so). I admit I
haven't thought much about whether the idea would actually work:
but there is a motivation to think about it.

Also, whether or not one library provides the same
representation .. there is a question of which one to
use, given one has an eye for the future: we're
going to have 6 variants of, for example:

sin z

instead of just 3. Given that, suppose you wished
to write some new functions .. what would you do?
Use the C version? The C++ version? Both?

Note that my typedef solution *precludes* doing both.
If a typedef is used as a specialisation, then

complex<float>

and

float _Complex

will actually be the same type, which has implications
for overloading.

MAYBE the only thing that can be done is provide
a macro which tells if these two types are representation
compatible.. but this may still cause aliasing problems
(see previous discussion where my assumptions aliasing
pointers were quashed by aliasing rules).

It's going to be a real pain if one has C libraries
for complex arithmetic and also some C++ libraries:
if the objects are matricies .. conversions would be
too slow to contemplate.

--
John Skaller <skaller at users dot sf dot net>
Try Felix, the successor to C++ http://felix.sf.net


---
[ 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 ]
Back to top
kanze
Guest





PostPosted: Thu Aug 17, 2006 4:12 pm    Post subject: Re: C++ and C99 complex Reply with quote

"P.J. Plauger" wrote:
Quote:
"skaller" <skaller (AT) users (DOT) sourceforge.net> wrote in message
news:pan.2006.08.11.01.33.34.253488 (AT) users (DOT) 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.)

Quote:
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 orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 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 ]
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.