 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Ioannis Vranos Guest
|
Posted: Tue Sep 21, 2004 11:27 am Post subject: Proposal: New types in C++0x |
|
|
Since there is the need of a new 64-bit integer type, the approach taken
should be extensible.
What about introducing int64 being exactly 64 bit, int32 being exactly
32 bits and int16 being exactly 16 bits, and making short and int
equivalent to int16, and long being equivalent to int32?
--
Ioannis Vranos
http://www23.brinkster.com/noicys
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Ulrich Eckhardt Guest
|
Posted: Tue Sep 21, 2004 6:28 pm Post subject: Re: Proposal: New types in C++0x |
|
|
Ioannis Vranos wrote:
| Quote: | Since there is the need of a new 64-bit integer type, the approach taken
should be extensible.
|
There is no need for a 'new 64 bit integer type', what makes you think so?
Don't the ones defined in stdint.h(which is IIRC C99) suffice?
| Quote: | What about introducing int64 being exactly 64 bit, int32 being exactly
32 bits and int16 being exactly 16 bits, and making short and int
equivalent to int16, and long being equivalent to int32?
|
Bad idea, since this breaks compatibility with existing systems.
Uli
--
FAQ: http://parashift.com/c++-faq-lite/
/* bittersweet C++ */
default: break;
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Ioannis Vranos Guest
|
Posted: Tue Sep 21, 2004 8:21 pm Post subject: Re: Proposal: New types in C++0x |
|
|
To be more obvious, what I propose is:
int16 is introduced and is an exact 16-bit type (of course additional
padding bits are allowed). int and short become equivalent of it.
That is, signed int16, int16, signed, signed int, int, signed short,
short to be all equivalent. The same for the unsigned equivalents. That
is unsigned int16 to be the same as unsigned int and unsigned, etc.
int32 is introduced and holds exactly 32-bit values. long becomes
another name of it, as was the case with the above.
signed int32, int32, signed long, long are all the same.
int64 is introduced and holds 64-bit values. signed int64 is equivalent
and unsigned int64 is the unsigned type.
So we can say:
int64 x;
int32 *p = new int32[10];
long *pp = p;
etc.
--
Ioannis Vranos
http://www23.brinkster.com/noicys
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Ioannis Vranos Guest
|
Posted: Tue Sep 21, 2004 10:44 pm Post subject: Re: Proposal: New types in C++0x |
|
|
Ulrich Eckhardt wrote:
| Quote: | There is no need for a 'new 64 bit integer type', what makes you think so?
Don't the ones defined in stdint.h(which is IIRC C99) suffice?
|
Personally I do not like "exotic" typedefs (that is typedefs of
non-standard built in types).
My proposal is extensible and does not use long long.
| Quote: | What about introducing int64 being exactly 64 bit, int32 being exactly
32 bits and int16 being exactly 16 bits, and making short and int
equivalent to int16, and long being equivalent to int32?
Bad idea, since this breaks compatibility with existing systems.
|
What do you mean?
--
Ioannis Vranos
http://www23.brinkster.com/noicys
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Victor Bazarov Guest
|
Posted: Tue Sep 21, 2004 10:49 pm Post subject: Re: Proposal: New types in C++0x |
|
|
Ioannis Vranos wrote:
| Quote: | To be more obvious, what I propose is:
[...]
So we can say:
int64 x;
int32 *p = new int32[10];
long *pp = p;
^^^^^^^^^^^^^ |
This should not work on a system where 'long' has more than 32 bits.
V
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Ioannis Vranos Guest
|
Posted: Tue Sep 21, 2004 10:50 pm Post subject: Re: Proposal: New types in C++0x |
|
|
Oliver S. wrote:
| Quote: | That would break the platform-independence of the language-definition.
But afaik C++0x will adopt C99's long long data-type which maps to a
64-bit integer on some machines.
|
long long in C99 is at least 64-bits, so it can't be less than 64-bits
in any C99 compiler.
--
Ioannis Vranos
http://www23.brinkster.com/noicys
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Daryle Walker Guest
|
Posted: Wed Sep 22, 2004 9:53 am Post subject: Re: Proposal: New types in C++0x |
|
|
In article <cinam2$1aje$2 (AT) ulysses (DOT) noc.ntua.gr>,
Ioannis Vranos <ivr (AT) guesswh (DOT) at.grad.com> wrote:
| Quote: | Since there is the need of a new 64-bit integer type, the approach taken
should be extensible.
|
Wouldn't carrying over C-1999's "long long" type suffice? I think it
has to be at least 64 bits.
| Quote: | What about introducing int64 being exactly 64 bit, int32 being exactly
32 bits and int16 being exactly 16 bits, and making short and int
equivalent to int16, and long being equivalent to int32?
|
A problem with these proposals is that they show that everyone is so
ingrained with the "char: 8 bits, short: 16 bits, long: 32 bits, int: 32
bits (but occasionally 16)" system that you all forget that the original
types didn't assume those sizes. In fact, some computers used bit
lengths that were not powers of two (e.g. 9-bit bytes).
I think "int" was supposed to be the processor's natural size. So, for
64-bit computers, "int" should get bumped up to 64 bits, with "long" at
64 or 128 bits and "short" at 32 bits, needing a "short short" at 16
bits. Yes, the "common platform assumptions" I gave in the previous
paragraph lead to the C committee extending the system in the wrong
direction (to keep compatibility with the common assumptions).
--
Daryle Walker
Mac, Internet, and Video Game Junkie
dwalker07 AT snet DOT net
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Jack Klein Guest
|
Posted: Wed Sep 22, 2004 10:00 am Post subject: Re: Proposal: New types in C++0x |
|
|
On 21 Sep 2004 07:27:32 -0400, Ioannis Vranos
<ivr (AT) guesswh (DOT) at.grad.com> wrote in comp.lang.c++.moderated:
| Quote: | Since there is the need of a new 64-bit integer type, the approach taken
should be extensible.
What about introducing int64 being exactly 64 bit, int32 being exactly
32 bits and int16 being exactly 16 bits, and making short and int
equivalent to int16, and long being equivalent to int32?
|
Multi-posting to both comp.lang.c++ and comp.lang.c++.moderated is
poor netiquette.
I posted a reply to your longer post in the unmoderated group as to
why I think this is a poor idea, and suggesting that you look at the
prior work already standardized in C in 1999, which will be
standardized in C++ some day.
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Alberto Barbati Guest
|
Posted: Wed Sep 22, 2004 10:03 am Post subject: Re: Proposal: New types in C++0x |
|
|
Ioannis Vranos wrote:
| Quote: | Ulrich Eckhardt wrote:
There is no need for a 'new 64 bit integer type', what makes you think so?
Don't the ones defined in stdint.h(which is IIRC C99) suffice?
Personally I do not like "exotic" typedefs (that is typedefs of
non-standard built in types).
|
That's your personal opinion. Frankly, I don't care how intXX_t is
typedef'd as long as it works. Moreover, what makes you think you need
non-standard built-in types to define them? It's not necessarily so.
| Quote: | My proposal is extensible and does not use long long.
|
This is a moot point. I find the typedef solution as extendable as your
proposal, if not more. The fact that you don't use long long is
inessential here, as even typedefs need not necessarily use long long.
| Quote: | What about introducing int64 being exactly 64 bit, int32 being exactly
32 bits and int16 being exactly 16 bits, and making short and int
equivalent to int16, and long being equivalent to int32?
Bad idea, since this breaks compatibility with existing systems.
What do you mean?
|
For example, on the x86 platform, int is a 32-bit type. I guess that 80%
of the programs out there rely on that fact. If you make it a 16-bit
type, you will probably break at least half of the programs ever written
on that platform.
This kind of discussion cyclically reappear. Each time a religion war
starts and ends with no winners nor losers. Basic types have been
defined with implementation-defined sizes since the beginning. Having
typedefs for fixed-size types as a pure-library extension is good so you
can have both approaches and use the one that you prefer. Sure, you
might prefer to have the other way around. That solution would be just
as good, no better and no worse. Changing the definitions now is going
to be costly (in terms of development of new tools, training,
bugfixing), confusing (it may take years before all compilers conforms
to the new definition) and dangerous (because it potentially breaks
existing code). It's no surprise that no one wants to take the risk to
abandon a good solution for an equally good solution if the price is so
high. Would you do it?
You'd better try to live with that.
Regards,
Alberto
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Ioannis Vranos Guest
|
Posted: Wed Sep 22, 2004 10:07 am Post subject: Re: Proposal: New types in C++0x |
|
|
Victor Bazarov wrote:
| Quote: | Ioannis Vranos wrote:
To be more obvious, what I propose is:
[...]
So we can say:
int64 x;
int32 *p = new int32[10];
long *pp = p;
^^^^^^^^^^^^^
This should not work on a system where 'long' has more than 32 bits.
|
However current code assuming that long holds more than 32-bit values is
not portable.
Plus a "replace all" of long to int64 in the code, would also fix that
portably.
--
Ioannis Vranos
http://www23.brinkster.com/noicys
[ 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
|
Posted: Wed Sep 22, 2004 6:27 pm Post subject: Re: Proposal: New types in C++0x |
|
|
Ioannis Vranos <ivr (AT) guesswh (DOT) at.grad.com> wrote
| Quote: | Oliver S. wrote:
That would break the platform-independence of the
language-definition. But afaik C++0x will adopt C99's long long
data-type which maps to a 64-bit integer on some machines.
long long in C99 is at least 64-bits, so it can't be less than 64-bits
in any C99 compiler.
|
I don't know if there is a C99 compiler for the Unisys 2200, but if so,
long long would almost certainly be 72 bits.
--
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
|
Posted: Wed Sep 22, 2004 6:29 pm Post subject: Re: Proposal: New types in C++0x |
|
|
Ioannis Vranos <ivr (AT) guesswh (DOT) at.grad.com> wrote
| Quote: | To be more obvious, what I propose is:
int16 is introduced and is an exact 16-bit type (of course additional
padding bits are allowed).
|
That's going to slow performance notably on machines which don't have
native 16 bit types.
| Quote: | int and short become equivalent of it.
|
Making int a 16 bit type will break a lot of existing code -- not 100%
portable code, but code which is sufficiently portable for a lot of use.
The de facto standard size of int today is 32 bits, at least for the
more common platforms: Windows, all of the mainstream Unix, IBM
mainframes... In fact, the only exception I know is the Unisys 2200,
where int is 36 bits, but I imagine that there are smaller, embedded
processors where it is 16 bits.
| Quote: | That is, signed int16, int16, signed, signed int, int, signed short,
short to be all equivalent. The same for the unsigned equivalents.
That is unsigned int16 to be the same as unsigned int and unsigned,
etc.
int32 is introduced and holds exactly 32-bit values. long becomes
another name of it, as was the case with the above.
|
That will break my code, too. On my platform, long is 64 bits. I think
that this is more or less the de facto standard outside of the Windows
world (although most compilers also support a 32 bit mode for legacy
code).
It's an almost certainty, I think, that the next C++ standard will
contain long long -- while I find it a mistaken solution to the problem,
it would be an even bigger mistake to break C compatibility for
something this fundamental. I suspect that we will also see stdint.h in
some form. That would seem to solve the problem.
--
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 |
|
 |
Victor Bazarov Guest
|
Posted: Wed Sep 22, 2004 6:50 pm Post subject: Re: Proposal: New types in C++0x |
|
|
Ioannis Vranos wrote:
| Quote: | Victor Bazarov wrote:
Ioannis Vranos wrote:
To be more obvious, what I propose is:
[...]
So we can say:
int64 x;
int32 *p = new int32[10];
long *pp = p;
^^^^^^^^^^^^^
This should not work on a system where 'long' has more than 32 bits.
However current code assuming that long holds more than 32-bit values is
not portable.
|
Any code _assuming_ a particular size of 'long' is wrong whether it is
more than 32 bits or exactly 32 bits. What I said is still true, on the
systems where 'long' is more than 32 bits, the statement
long *pp = p;
from your program will NOT work.
| Quote: | Plus a "replace all" of long to int64 in the code, would also fix that
portably.
|
How would it fix that?
int64 *pp = p;
is still NOT going to work.
Victor
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Markus Elfring Guest
|
Posted: Wed Sep 22, 2004 6:58 pm Post subject: Re: Proposal: New types in C++0x |
|
|
| Quote: | long long in C99 is at least 64-bits, so it can't be less than 64-bits
in any C99 compiler.
|
How will integer values with more bits be implemented?
- Will the word "long" be repeated more than twice?
- Can the bit count be specified for a "variable" int type?
example: int<256> x;
- Is a template appropriate?
[ 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
|
Posted: Fri Sep 24, 2004 11:21 am Post subject: Re: Proposal: New types in C++0x |
|
|
Alberto Barbati <AlbertoBarbati (AT) libero (DOT) it> wrote
| Quote: | Ioannis Vranos wrote:
|
[...]
| Quote: | What about introducing int64 being exactly 64 bit, int32 being
exactly 32 bits and int16 being exactly 16 bits, and making short
and int equivalent to int16, and long being equivalent to int32?
Bad idea, since this breaks compatibility with existing systems.
What do you mean?
For example, on the x86 platform, int is a 32-bit type. I guess that
80% of the programs out there rely on that fact. If you make it a
16-bit type, you will probably break at least half of the programs
ever written on that platform.
|
Just a couple of nits. First, it isn't just the x86 platforms. Int has
been 32 bits on all mainstream general purpose computers for the last
ten or twelve years, I think. About the only exceptions I can think of
among the general purpose computers are the Unisys mainframes: the 2200
line uses 36 bit ints, and the (now out of production) series A used 48
bit ints.
Secondly, I actually know of very few programs which count on int being
exactly 32 bits. Most, however (including my own, when I know that it
will only run on a general purpose computer), do assume that int is fine
for values well over 32000 -- and I'd guess here that making int 16 bits
would break a lot more than 80% of the existing programs.
For better or for worse, most people have gotten out of the habit of
considering the possibility that int might overflow unless they are
dealing with very large values. Even programs which validate input
against INT_MAX (using an expression which depends on what is later done
with the number) are likely to be rendered useless if INT_MAX is too
small.
--
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 |
|
 |
|
|
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
|
|