C99 _Complex and C++ complex<> interoperability.

Smith-Rowland, Edward M ESmith-rowland@alionscience.com
Fri Mar 16 20:14:00 GMT 2007



-----Original Message-----
From: gdr@cs.tamu.edu [mailto:gdr@cs.tamu.edu] 
Sent: Friday, March 16, 2007 8:54 AM
To: Benjamin Kosnik
Cc: Smith-Rowland, Edward M; libstdc++@gcc.gnu.org
Subject: Re: C99 _Complex and C++ complex<> interoperability.


Benjamin Kosnik <bkoz@redhat.com> writes:

| > | 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.
| > It is not in the ISO C++ standard.  It is purely a libstdc++ 
| > implementation detail.  However, I've taken deliberately chosen to 
| > make  ISO C++ std::complex<> and ISO C _Complex interoperate where 
| > possible.  It is therefore a GCC extension that I'm not willing to 
| > formally document at this moment because there are other issues that

| > are resolved yet and that might change in the future.
| 
| FWIW, I too think this is cool and where the standard should be 
| headed.
| 
| If somebody was to write up the current libstdc++ behavior as 
| standardese or a paper, (likely that would also mean attending a 
| meeting or two and trying to get it discussed), and if Red Hat is a 
| voting member of ISO C++, I would vote yes.

:-) [ seriously, I thought RH is a voting member, no? ]

I would vote "over my dead body".

Essentially, we would have two complex number data types in the
language, with one being in library and one being in the core language.
There already are widespread FUDs about library data types being slower
that those that are in the core language that I have to fight every day
that I really don't want to fuel it anymore. Furthermore, we would have
incomplatible syntax, with incompatible conversion rules fore
essentially the same notion.  I don't think that is should be a standard
future.

-- Gaby

I am sympathetic both to fighting template class FUD (I work for someone
who thinks templates are slow, uses malloc and free...) and to the
general repulsiveness of adding the _Complex keyword to C++.  In fact,
my recent experiences with the TR1 special math functions have made me
half-jokingly think that C++ should deprecate or remove float, double,
and long double in favor of
something_that_acts_more_like_a_real_number<dammit>.  I think that
floating point numbers are a too blunt instrument for some of the
functions - especially the hypergeometric functions.  Another day.

I can't see proposing the latter or that such a proposal would ever win.
On the other hand, it is unfortunate that there may be a permanent fork
in the road for C and C++ on this.

I wonder if we couldn't say something like this:  Since, hopefully, C++
is required to implement complex in the obvious way with two packed
numbers ...
No, that won't work because _Complex must be paired with float or double
or long double and that really is a front-end issue.  I was hoping for
some library hackery.

Ed



More information about the Libstdc++ mailing list