Topic: Defect report: moneypunct::frac_digits returns int not unsigned
Author: roshan_naik@yahoo.com
Date: Tue, 20 Aug 2002 21:03:48 GMT Raw View
James Kanze wrote:
> Because the language was designed to work that way. Since the beginning
> of C, int has been the natural type for integral values, with other
> types available for special purposes, when needed.
>
That statement makes it sound like the unsigned int was never part of the
C/C++ language design, or some kind of language design mistake.
--Roshan
---
[ 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.jamesd.demon.co.uk/csc/faq.html ]
Author: nobody <nobody@localhost.ucar.edu>
Date: Tue, 20 Aug 2002 22:34:47 GMT Raw View
roshan_naik@yahoo.com wrote:
>
> James Kanze wrote:
>
> > Because the language was designed to work that way. Since the beginning
> > of C, int has been the natural type for integral values, with other
> > types available for special purposes, when needed.
> >
>
> That statement makes it sound like the unsigned int was never part of the
> C/C++ language design, or some kind of language design mistake.
I believe that one can coherently argue that in many respect the inclusion
of the unsigned in type WAS a language design mistake. The big problem is
that the promotion rules cause terrible problems in the evaluation of
expressions. The switchover from Classic C's "unsigned-preserving"
promotions to C89's and C++'s "value-preserving" promotions helps but does
not fix the problems entirely because there is no common type that can
hold _all_ possible integral values. Thus, expressions that contain both
signed and unsigned ints have everything "promoted" to unsigned. This
includes comparison expressions, and so a negative signed int will NOT,
in most implementations, be less than an unsigned int that has the value
zero!!! Unreasonable to make such a comparison, you say? Have you never
wanted to do something like this (where p and q are pointers):
if ( (q - p) < sizeof(something) ) { ... }
That's not safe, it needs to have sizeof cast to a signed type to work.
Pascal's policy of making all the integral types subranges of integer
allows for mixed expressions involving types with different subranges
to be evaluated coherently by promoting everything to integer.
My policy is to avoid unsigned int when I intend the result to be
used in arithmetic expressions that may involve comparisons. Unsigned
int is to be reserved for things like bit maps. (Note that these
limitations don't apply to unsigned short and unsigned char on
implementations where all their values can be held in an int, because
they will promote correctly in such cases.)
nobody
---
[ 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.jamesd.demon.co.uk/csc/faq.html ]
Author: kanze@gabi-soft.de (James Kanze)
Date: Wed, 21 Aug 2002 17:07:35 GMT Raw View
roshan_naik@yahoo.com wrote in message
news:<3D62AD7B.14BE04D4@yahoo.com>...
> James Kanze wrote:
> > Because the language was designed to work that way. Since the
> > beginning of C, int has been the natural type for integral values,
> > with other types available for special purposes, when needed.
> That statement makes it sound like the unsigned int was never part of
> the C/C++ language design, or some kind of language design mistake.
Not at all. That statement makes it sound like unsigned int was made
part of the language in order to handle special cases, where a normal
int wasn't appropriate.
--
James Kanze mailto:jkanze@caicheuvreux.com
Conseils en informatique orient e objet/
Beratung in objektorientierter Datenverarbeitung
---
[ 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.jamesd.demon.co.uk/csc/faq.html ]
Author: John Nagle <nagle@animats.com>
Date: Wed, 21 Aug 2002 17:08:23 GMT Raw View
nobody wrote:
> roshan_naik@yahoo.com wrote:
>
>>James Kanze wrote:
>>
>>
>>>Because the language was designed to work that way. Since the beginning
>>>of C, int has been the natural type for integral values, with other
>>>types available for special purposes, when needed.
>>>
>>>
>>That statement makes it sound like the unsigned int was never part of the
>>C/C++ language design, or some kind of language design mistake.
> I believe that one can coherently argue that in many respect the inclusion
> of the unsigned in type WAS a language design mistake.
....
> Pascal's policy of making all the integral types subranges of integer
> allows for mixed expressions involving types with different subranges
> to be evaluated coherently by promoting everything to integer.
I once wrote a paper titled "Type integer considered harmful".
This was back when Ada was being designed. My position was
that, similar to Pascal-like "subranges", there should simply
be "ranges" for numeric variables. The intent was to get the
same answer on all platforms.
Key to this was the rule that the compiler must size
intermediate values such that overflow cannot occur, unless
a range violation for a user declared variable would also
occur. It turns out that this doesn't force multiple-precision
arithmetic excessively. Again, the goal was the same answer
on all platforms.
This was too radical, although numerically, it's right.
C and C++ try to deal with numerical ranges lexically,
which doesn't work all that well. But it's too late
to change this. We also have more uniform CPU architecture
now; when I wrote that, there were many CPUs running with
word sizes that weren't powers of 2. So it's less of an
issue, now that we don't have to support machines with
"int" sizes of 18, 24, 36, 48, and 56 bits.
John Nagle
Animats
---
[ 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.jamesd.demon.co.uk/csc/faq.html ]
Author: roshan_naik@yahoo.com
Date: Wed, 21 Aug 2002 22:49:14 GMT Raw View
James Kanze wrote:
> Because the language was designed to work that way. Since the beginning
> of C, int has been the natural type for integral values, with other
> types available for special purposes, when needed.
>
That statement makes it sound like "unsigned int" was never meant to be part
of c/c++ or some kind of embarrassing mistake in language design.
--Roshan
---
[ 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.jamesd.demon.co.uk/csc/faq.html ]
Author: John Levon <moz@compsoc.man.ac.uk>
Date: Sun, 11 Aug 2002 08:52:41 GMT Raw View
James Kanze wrote:
> I disagree (sort of). Good programming practice is to use int if there
> are no overwhelming reasons to do otherwise, at least in C and C++.
Out of interest, what is the rationale behind this statement ?
thanks
john
---
[ 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.jamesd.demon.co.uk/csc/faq.html ]
Author: kanze@gabi-soft.de (James Kanze)
Date: Mon, 12 Aug 2002 18:52:18 GMT Raw View
John Levon <moz@compsoc.man.ac.uk> wrote in message
news:<aj4dlp$k48$1@news7.svr.pol.co.uk>...
> James Kanze wrote:
> > I disagree (sort of). Good programming practice is to use int if
> > there are no overwhelming reasons to do otherwise, at least in C and
> > C++.
> Out of interest, what is the rationale behind this statement ?
Because the language was designed to work that way. Since the beginning
of C, int has been the natural type for integral values, with other
types available for special purposes, when needed.
--
James Kanze mailto:jkanze@caicheuvreux.com
Conseils en informatique orient e objet/
Beratung in objektorientierter Datenverarbeitung
---
[ 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.jamesd.demon.co.uk/csc/faq.html ]