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 

C99 designated initializers in C++
Goto page 1, 2  Next
 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Retlak Yezdegird
Guest





PostPosted: Sat Sep 25, 2004 10:36 am    Post subject: C99 designated initializers in C++ Reply with quote



What is the status of C99 "designated initializers" in C++ ?

{Not supported by the Standard Language. -mod/fwg}


___________________________________________________
Check-out GO.com
GO get your free GO E-Mail account with expanded storage of 6 MB!
http://mail.go.com



[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
kanze@gabi-soft.fr
Guest





PostPosted: Mon Sep 27, 2004 2:09 pm    Post subject: Re: C99 designated initializers in C++ Reply with quote



Retlak Yezdegird <retlak (AT) go (DOT) com> wrote


Quote:
What is the status of C99 "designated initializers" in C++ ?

{Not supported by the Standard Language. -mod/fwg}

We know that:-). But what is the status. Will they be supported by the
next version of the standard? Or we don't know yet? Or there will
probably be an alternative? Or...

Note that even if the committee has yet to vote, there are some
extensions in C99, like long long, which I think are almost sure to be
adopted. Others, such as VLAs, pose a few problems, and can only be
adopted if those problems are solved. Which supposes that someone wants
them enough to invest the time necessary to solve them. And some, like
C's version of complex, are simple contradictions with current C++, and
will certainly not be adopted. I, for one, would be curious as to which
category "designated initializers" comes under. (The existance of
constructors makes them much less interesting than in C, so I could
easily imagine that if they do pose a few problems, there won't be many
people with enough interest to invest the time to solve them.)

--
James Kanze GABI Software http://www.gabi-soft.fr
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

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Francis Glassborow
Guest





PostPosted: Mon Sep 27, 2004 8:49 pm    Post subject: Re: C99 designated initializers in C++ Reply with quote



In article <d6652001.0409270032.7805900e (AT) posting (DOT) google.com>,
[email]kanze (AT) gabi-soft (DOT) fr[/email] writes
Quote:
Retlak Yezdegird <retlak (AT) go (DOT) com> wrote in message
news:<4085383.1096038235727.JavaMail.retlak@gomailjtp03>...

What is the status of C99 "designated initializers" in C++ ?

{Not supported by the Standard Language. -mod/fwg}

We know that:-). But what is the status. Will they be supported by the
next version of the standard? Or we don't know yet? Or there will
probably be an alternative? Or...

I think this is part of a larger topic, that of initialisation syntax in
C++. Something that I am currently working on for WG21.


--
Francis Glassborow ACCU
Author of 'You Can Do It!' see http://www.spellen.org/youcandoit
For project ideas and contributions: http://www.spellen.org/youcandoit/projects


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Glen Low
Guest





PostPosted: Tue Sep 28, 2004 9:33 pm    Post subject: Re: C99 designated initializers in C++ Reply with quote

Quote:
And some, like
C's version of complex, are simple contradictions with current C++, and
will certainly not be adopted.

I suppose you mean the complex.h header in C99 and the complex header
in C++? Because if you don't #include the former, you can still
reconcile complex usage in both languages: C99 uses _Complex and _I
etc. and you could write (as I have and gcc libstdc++ has, to some
degree) a std::complex that converts from a suitable _Complex number.

Cheers,
Glen Low, Pixelglow Software
www.pixelglow.com

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Retlak
Guest





PostPosted: Wed Sep 29, 2004 9:51 am    Post subject: Re: C99 designated initializers in C++ Reply with quote

Francis Glassborow <francis (AT) robinton (DOT) demon.co.uk> wrote


Quote:
I think this is part of a larger topic, that of initialisation syntax in
C++. Something that I am currently working on for WG21.

FWIW, I think it's desirable to adopt C99's designated initializers in
C++ if possible, simply to make it easier to compile C with a C++
compiler.

I know the C people haven't tried very hard to keep C a subset of C++,
which IMHO is a pity, but it's still a worthy objective to keep C++ as
near as reasonably possible to a superset of C as long as there are no
bad consequences.

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
kanze@gabi-soft.fr
Guest





PostPosted: Thu Sep 30, 2004 10:40 am    Post subject: Re: C99 designated initializers in C++ Reply with quote

[email]glenlow (AT) pixelglow (DOT) com[/email] (Glen Low) wrote in message
news:<9215d7ac.0409280044.61565950 (AT) posting (DOT) google.com>...

Quote:
And some, like C's version of complex, are simple contradictions
with current C++, and will certainly not be adopted.

I suppose you mean the complex.h header in C99 and the complex header
in C++?

No. I mean the definition of complex numbers in C, and their definition
in C++. I don't have any inside information, so I can't be sure, but I
would guess that the probabilities of the next version of C++ adopting
the complex number types from C to be very close to zero.

Quote:
Because if you don't #include the former, you can still reconcile
complex usage in both languages: C99 uses _Complex and _I etc. and you
could write (as I have and gcc libstdc++ has, to some degree) a
std::complex that converts from a suitable _Complex number.

In all implementations that I am aware of, the conversion between the
two is as simple as a reinterpret_cast. The real problem comes with
naming them -- how do you declare a C function which takes a _Complex in
C++?

There is a fundamental problem here. As far as I know, at the type C++
first started to address the issue of complex, there was no expressed
intention in the C committee of adding such a type. And a class with
overloaded operators (and later a template class) are the natural
solutions in C++. Once C++ had complex, and C wanted to add it, there
simply wasn't a compatible way. C couldn't adopt the C++ solution,
since it is based on techniques that don't exist in C. About the best
we can do is to take steps to ensure that a reinterpret_cast between the
two is guaranteed to work -- from what I've heard elsewhere, there are
strong arguments for defining the actual layout anyway, independantly of
C/C++ compatibililty, and perhaps requiring _Complex to work in C++ as
well (although without any of the built-in operations).

The next issue on the floor seems to be decimal arithmetic. This one
seems to have started in C, so I guess that there is some hope of
compatibility. (This isn't meant to reflect on the attitudes of the two
committees. It's just that C has a lot less means to work with.
Anything C adopts can probably be adopted fairly easily to C++. Whereas
the reverse is far from true.)

--
James Kanze GABI Software http://www.gabi-soft.fr
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

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Francis Glassborow
Guest





PostPosted: Thu Sep 30, 2004 2:03 pm    Post subject: Re: C99 designated initializers in C++ Reply with quote

In article <4e9c40c6.0409280628.58a793a (AT) posting (DOT) google.com>, Retlak
<retlak (AT) go (DOT) com> writes
Quote:
Francis Glassborow <francis (AT) robinton (DOT) demon.co.uk> wrote in message
news:<rgbVmVVayDWBFw5$@robinton.demon.co.uk>...

I think this is part of a larger topic, that of initialisation syntax
in
C++. Something that I am currently working on for WG21.

FWIW, I think it's desirable to adopt C99's designated initializers in
C++ if possible, simply to make it easier to compile C with a C++
compiler.

I am far from sure that that in itself is sufficient motivation. I would
want to see a positive benefit to C++.


--
Francis Glassborow ACCU
Author of 'You Can Do It!' see http://www.spellen.org/youcandoit
For project ideas and contributions:
http://www.spellen.org/youcandoit/projects


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
P.J. Plauger
Guest





PostPosted: Fri Oct 01, 2004 4:59 pm    Post subject: Re: C99 designated initializers in C++ Reply with quote

<kanze (AT) gabi-soft (DOT) fr> wrote


Quote:
glenlow (AT) pixelglow (DOT) com (Glen Low) wrote in message
news:<9215d7ac.0409280044.61565950 (AT) posting (DOT) google.com>...

And some, like C's version of complex, are simple contradictions
with current C++, and will certainly not be adopted.

I suppose you mean the complex.h header in C99 and the complex header
in C++?

No. I mean the definition of complex numbers in C, and their definition
in C++. I don't have any inside information, so I can't be sure, but I
would guess that the probabilities of the next version of C++ adopting
the complex number types from C to be very close to zero.

From a language standpoint, I agree. But the emerging C++ library TR
(aka TR1) has already picked up all the complex library stuff from C99.
It's really quite easy to make the two flavors of complex get along.

Quote:
Because if you don't #include the former, you can still reconcile
complex usage in both languages: C99 uses _Complex and _I etc. and you
could write (as I have and gcc libstdc++ has, to some degree) a
std::complex that converts from a suitable _Complex number.

In all implementations that I am aware of, the conversion between the
two is as simple as a reinterpret_cast. The real problem comes with
naming them -- how do you declare a C function which takes a _Complex in
C++?

See the draft TR1. The shipping Dinkumware C/C++ library solved this
problem years ago.

Quote:
There is a fundamental problem here. As far as I know, at the type C++
first started to address the issue of complex, there was no expressed
intention in the C committee of adding such a type. And a class with
overloaded operators (and later a template class) are the natural
solutions in C++. Once C++ had complex, and C wanted to add it, there
simply wasn't a compatible way. C couldn't adopt the C++ solution,
since it is based on techniques that don't exist in C. About the best
we can do is to take steps to ensure that a reinterpret_cast between the
two is guaranteed to work -- from what I've heard elsewhere, there are
strong arguments for defining the actual layout anyway, independantly of
C/C++ compatibililty, and perhaps requiring _Complex to work in C++ as
well (although without any of the built-in operations).

The C++ committee has already (informally? agreed to require layout
compatibility between C++ complex and C complex -- which is really
the old Fortray layout.

Quote:
The next issue on the floor seems to be decimal arithmetic. This one
seems to have started in C, so I guess that there is some hope of
compatibility. (This isn't meant to reflect on the attitudes of the two
committees. It's just that C has a lot less means to work with.
Anything C adopts can probably be adopted fairly easily to C++. Whereas
the reverse is far from true.)

We'll try to keep them more compatible. I'm in charge of the decimal
efforts in both committees, not that I've done that much these past
six months (on decimal, that is).

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



[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
Walter
Guest





PostPosted: Fri Oct 01, 2004 5:17 pm    Post subject: Re: C99 designated initializers in C++ Reply with quote


"Retlak" <retlak (AT) go (DOT) com> wrote

Quote:
Francis Glassborow <francis (AT) robinton (DOT) demon.co.uk> wrote


I think this is part of a larger topic, that of initialisation syntax
in
C++. Something that I am currently working on for WG21.

FWIW, I think it's desirable to adopt C99's designated initializers in
C++ if possible, simply to make it easier to compile C with a C++
compiler.

I know the C people haven't tried very hard to keep C a subset of C++,
which IMHO is a pity, but it's still a worthy objective to keep C++ as
near as reasonably possible to a superset of C as long as there are no
bad consequences.

I agree, and Digital Mars C++ supports C99 designated initializers as an
extension to C++ (as well as C99 complex numbers and other improvements).

-Walter
www.digitalmars.com free C/C++/D compilers


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Walter
Guest





PostPosted: Fri Oct 01, 2004 5:21 pm    Post subject: Re: C99 designated initializers in C++ Reply with quote


<kanze (AT) gabi-soft (DOT) fr> wrote

Quote:
glenlow (AT) pixelglow (DOT) com (Glen Low) wrote in message
news:<9215d7ac.0409280044.61565950 (AT) posting (DOT) google.com>...
In all implementations that I am aware of, the conversion between the
two is as simple as a reinterpret_cast. The real problem comes with
naming them -- how do you declare a C function which takes a _Complex in
C++?

There is a fundamental problem here. As far as I know, at the type C++
first started to address the issue of complex, there was no expressed
intention in the C committee of adding such a type. And a class with
overloaded operators (and later a template class) are the natural
solutions in C++. Once C++ had complex, and C wanted to add it, there
simply wasn't a compatible way. C couldn't adopt the C++ solution,
since it is based on techniques that don't exist in C. About the best
we can do is to take steps to ensure that a reinterpret_cast between the
two is guaranteed to work -- from what I've heard elsewhere, there are
strong arguments for defining the actual layout anyway, independantly of
C/C++ compatibililty, and perhaps requiring _Complex to work in C++ as
well (although without any of the built-in operations).

I'd just deprecate C++'s class complex and go with the C99 version. (The
only change programmers want to make to compile the obsolete code is to
rename the C++ complex.h to oldcomplex.h, and #include that instead. Not a
big deal.) What practical advantage does class complex have over C99
complex? I don't see one.


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Glen Low
Guest





PostPosted: Sun Oct 03, 2004 3:00 am    Post subject: Re: C99 designated initializers in C++ Reply with quote

Quote:
I'd just deprecate C++'s class complex and go with the C99 version. (The
only change programmers want to make to compile the obsolete code is to
rename the C++ complex.h to oldcomplex.h, and #include that instead. Not a
big deal.) What practical advantage does class complex have over C99
complex? I don't see one.

The syntactic sugar of function overloading.

std::complex <double> z = acos (z2);

might be easier to intuit, parse, remember than

double _Complex z = cacos (z2);

Cheers,
Glen Low, Pixelglow Software
www.pixelglow.com

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
Glen Low
Guest





PostPosted: Sun Oct 03, 2004 3:01 am    Post subject: Re: C99 designated initializers in C++ Reply with quote

Quote:
See the draft TR1. The shipping Dinkumware C/C++ library solved this
problem years ago.

Are you talking about using a C99 function with a C++ complex type
e.g.

std::complex <double> z1 (1.0, 2.0);
std::complex <double> z2 = cacos (z1); // call the C99 version

Sounds like that would require a whole lot of overloads similar in
spirit to <cmath> bringing in the standard math functions into the std
namespace and/or some sort of implicit conversion from std::complex
<double> to double _Complex.

(A URL to the work would be nice.)

Cheers,
Glen Low, Pixelglow Software
www.pixelglow.com

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
Ben Hutchings
Guest





PostPosted: Mon Oct 04, 2004 6:08 am    Post subject: Re: C99 designated initializers in C++ Reply with quote

P.J. Plauger wrote:
Quote:
kanze (AT) gabi-soft (DOT) fr> wrote in message
news:d6652001.0409290419.6adb02d5 (AT) posting (DOT) google.com...
snip
In all implementations that I am aware of, the conversion between the
two is as simple as a reinterpret_cast. The real problem comes with
naming them -- how do you declare a C function which takes a _Complex in
C++?
snip
The C++ committee has already (informally? agreed to require layout
compatibility between C++ complex and C complex -- which is really
the old Fortray layout.
snip


So presumably the answer to the question James Kanze asked, that I've
quoted above, is to write something like this in a common C/C++ header

#ifdef __cplusplus
# include <complex>
# define COMPLEX(T) ::std::complex<T>
#else
# define COMPLEX(T) T _Complex
#endif

end then to use COMPLEX() to declare complex parameter types?

--
Ben Hutchings
If you seem to know what you are doing, you'll be given more to do.

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
kanze@gabi-soft.fr
Guest





PostPosted: Mon Oct 04, 2004 6:54 pm    Post subject: Re: C99 designated initializers in C++ Reply with quote

"P.J. Plauger" <pjp (AT) dinkumware (DOT) com> wrote

Quote:
kanze (AT) gabi-soft (DOT) fr> wrote in message
news:d6652001.0409290419.6adb02d5 (AT) posting (DOT) google.com...

[email]glenlow (AT) pixelglow (DOT) com[/email] (Glen Low) wrote in message
news:<9215d7ac.0409280044.61565950 (AT) posting (DOT) google.com>...

And some, like C's version of complex, are simple
contradictions with current C++, and will certainly not be
adopted.

I suppose you mean the complex.h header in C99 and the complex
header in C++?

No. I mean the definition of complex numbers in C, and their
definition in C++. I don't have any inside information, so I can't
be sure, but I would guess that the probabilities of the next
version of C++ adopting the complex number types from C to be very
close to zero.

From a language standpoint, I agree. But the emerging C++ library TR
(aka TR1) has already picked up all the complex library stuff from
C99. It's really quite easy to make the two flavors of complex get
along.

In practice, I'll admit to being pretty sure that all implementations
are basically equivalent (in memory layout) to T[2], where the first T
is the real part, that the second the imaginary.

Quote:
Because if you don't #include the former, you can still reconcile
complex usage in both languages: C99 uses _Complex and _I
etc. and you could write (as I have and gcc libstdc++ has, to
some degree) a std::complex that converts from a suitable
_Complex number.

In all implementations that I am aware of, the conversion between
the two is as simple as a reinterpret_cast. The real problem comes
with naming them -- how do you declare a C function which takes a
_Complex in C++?

See the draft TR1. The shipping Dinkumware C/C++ library solved this
problem years ago.

There is a fundamental problem here. As far as I know, at the type
C++ first started to address the issue of complex, there was no
expressed intention in the C committee of adding such a type. And
a class with overloaded operators (and later a template class) are
the natural solutions in C++. Once C++ had complex, and C wanted
to add it, there simply wasn't a compatible way. C couldn't adopt
the C++ solution, since it is based on techniques that don't exist
in C. About the best we can do is to take steps to ensure that a
reinterpret_cast between the two is guaranteed to work -- from what
I've heard elsewhere, there are strong arguments for defining the
actual layout anyway, independantly of C/C++ compatibililty, and
perhaps requiring _Complex to work in C++ as well (although without
any of the built-in operations).

The C++ committee has already (informally? agreed to require layout
compatibility between C++ complex and C complex -- which is really the
old Fortray layout.

And, as far as I know, the only layout that has ever been used,
anywhere:-).

Quote:
The next issue on the floor seems to be decimal arithmetic. This
one seems to have started in C, so I guess that there is some hope
of compatibility. (This isn't meant to reflect on the attitudes of
the two committees. It's just that C has a lot less means to work
with. Anything C adopts can probably be adopted fairly easily to
C++. Whereas the reverse is far from true.)

We'll try to keep them more compatible. I'm in charge of the decimal
efforts in both committees, not that I've done that much these past
six months (on decimal, that is).

Well, given my current customer mix, decimal is a lot more important to
me than complex, so I'll keep my eyes open:-).

--
James Kanze GABI Software http://www.gabi-soft.fr
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

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
kanze@gabi-soft.fr
Guest





PostPosted: Mon Oct 04, 2004 6:55 pm    Post subject: Re: C99 designated initializers in C++ Reply with quote

"Walter" <walter (AT) digitalmars (DOT) nospamm.com> wrote

Quote:
kanze (AT) gabi-soft (DOT) fr> wrote in message
news:d6652001.0409290419.6adb02d5 (AT) posting (DOT) google.com...
[email]glenlow (AT) pixelglow (DOT) com[/email] (Glen Low) wrote in message
news:<9215d7ac.0409280044.61565950 (AT) posting (DOT) google.com>...
In all implementations that I am aware of, the conversion between
the two is as simple as a reinterpret_cast. The real problem comes
with naming them -- how do you declare a C function which takes a
_Complex in C++?

There is a fundamental problem here. As far as I know, at the type
C++ first started to address the issue of complex, there was no
expressed intention in the C committee of adding such a type. And a
class with overloaded operators (and later a template class) are the
natural solutions in C++. Once C++ had complex, and C wanted to add
it, there simply wasn't a compatible way. C couldn't adopt the C++
solution, since it is based on techniques that don't exist in C.
About the best we can do is to take steps to ensure that a
reinterpret_cast between the two is guaranteed to work -- from what
I've heard elsewhere, there are strong arguments for defining the
actual layout anyway, independantly of C/C++ compatibililty, and
perhaps requiring _Complex to work in C++ as well (although without
any of the built-in operations).

I'd just deprecate C++'s class complex and go with the C99
version. (The only change programmers want to make to compile the
obsolete code is to rename the C++ complex.h to oldcomplex.h, and
#include that instead. Not a big deal.) What practical advantage does
class complex have over C99 complex? I don't see one.

An implementation is allowed to (but not required to) make things like
std::complex<MyBigReal> work.

--
James Kanze GABI Software http://www.gabi-soft.fr
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

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
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.