Re: Proposal: New types in C++0x

From: Jack Klein (jackklein_at_spamcop.net)
Date: 09/22/04


Date: Tue, 21 Sep 2004 23:07:58 -0500

On Wed, 22 Sep 2004 02:08:41 +0300, Ioannis Vranos
<ivr@guesswh.at.grad.com> wrote in comp.lang.c++:

> 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?

Gee, you are only some 5 years behind the times, since the October,
1999 adoption of ISO 9899:1999 Programming Languages -- C.

Your proposal is actually poorly thought out and harmful. What of
platforms that don't have 16-bit objects at all? There are some, you
know, and C++ compilers for some of them.

> My proposal more thoroughly:
>
> int16 is introduced and is an exact 16-bit type (of course additional
> padding bits are allowed). int and short become equivalent of it.

If it has padding bits, it is not an exact-width 16-bit type.

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

This would break an extremely large amount of conforming, if not
strictly portable, code that expects ints to be at least 32 bits.
There are millions of lines of such code in existence in working
programs where portability to 16-bit platforms is not considered
important.

> int32 is introduced and holds exactly 32-bit values. long becomes
> another name of it, as was the case with the above.

On at least some 64-bit processor implementations, (un)signed long
will be 64 bits.

> signed int32, int32, signed long, long are all the same.
>
> unsigned long is another name of unsigned int32.
>
>
> int64 is introduced and holds 64-bit values. signed int64 is equivalent
> and unsigned int64 is the unsigned type.

The original 1989 ANSI standard mentioned the already popular
extension 'long long' for an integer type with at least 64 bits. It
has been standardized in C for 5 years, and will be standardized, with
that name, in C++.

Do you actually think that both C and C++ have completely avoided
specifying exact representations for the integer types for 30 plus
years because nobody thought of it before you did? If you want
exactly specified sizes and ranges for all the arithmetic types, you
know where to find Java.

And for a portable and standardized method of providing ways to
specify integer types with various attributes, including such
exact-width types as an implementation can support, do a web search
for "stdint.h", part of standard C.

Finally, the place to propose new features for C++ is in the moderated
group news:comp.std.c++, not here. Read the FAQ first, of course.

-- 
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


Relevant Pages

  • RfD - Object Extensions
    ... While there is general agreement that Object-Oriented Programming (OOP) ... Forth currently has no standard extension for this. ...
    (comp.lang.forth)
  • Re: RfD - Object Extensions
    ... While there is general agreement that Object-Oriented Programming (OOP) ... Forth currently has no standard extension for this. ...
    (comp.lang.forth)
  • Re: Is C99 the final C? (some suggestions)
    ... The C standard specifies what is UB and what's not. ... If you have multithreading, they you have to lock and unlock ... > your heap, or use other strategies to make sure one thread isn't in the middle ... Having a different set of condoned operators at each programming ...
    (comp.lang.c)
  • Re: Portability: Harmony between PC and microcontroller
    ... int is the natural integer type for the system. ... You are, perhaps unintentionally, paraphrasing the standard in a way ... One of the things that you might not realize is that the C programming ... In the real world, most embedded systems have more complex jobs to do, ...
    (comp.lang.c)
  • Re: Sequence points
    ... They have been in the Standard since the Standard first appeared in 1989, ... you still don't understand sequence points. ... in areas outside of programming. ... programmers are in fact unequal to the demands of assembler language, ...
    (comp.programming)