Topic: Sizeof !!?
Author: "Dag Henriksson" <dag.henriksson@quidsoft.se>
Date: Tue, 28 May 2002 00:46:09 GMT Raw View
"Eigil Hysv r" <eigil.hysvaer@eudoramail.com> wrote in message
news:Xns921B7AC7218FEeigilhysvaereudorama@194.19.1.61...
> > It's a common misunderstanding that sizeof can be used to determine
the
> > range of values that fit in an integral type (except 'unsigned
char').
> >
> What? Well, 'short' and 'unsigned short' have two different ranges of
values,
> but they contain the same amount of possible values. I really don't
> understand what you're taking about !!? Enlighten me :-)
What I'm talking about is that if, for example,
sizeof (unsigned long) == sizeof (unsigned int)
this does not mean that the unsigned int can hold all the values that
the unsigned long can.
'sizeof' does not tell you how many bits are actually used to store the
value, just the number of bytes the type occupies.
--
Dag Henriksson
---
[ 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: James Kanze <kanze@alex.gabi-soft.de>
Date: Tue, 28 May 2002 15:20:50 GMT Raw View
"Eigil Hysv=E6r" <eigil.hysvaer@eudoramail.com> writes:
|> "Dag Henriksson" <dag.henriksson@quidsoft.se> wrote in=20
|> news:acm2oo$qk9kh$1@ID-107109.news.dfncis.de:
|> > "Francis Glassborow" <francis.glassborow@ntlworld.com> wrote in mes=
sage
|> > news:CZJxv2BBdi78EwRR@robinton.demon.co.uk...
|> > It's a common misunderstanding that sizeof can be used to
|> > determine the range of values that fit in an integral type
|> > (except 'unsigned char').
|> What? Well, 'short' and 'unsigned short' have two different ranges
|> of values, but they contain the same amount of possible values.
Not necessarily. And just because sizeof(short) equals twice
sizeof(char), there is no guarantee that it can contain the square of
the number of values. (I know of one real machine where sizeof(int)
was six, but the number of values an int could contain was
significantly less than the number of values in a char raised to the
sixth power.)
--=20
James Kanze mailto:kanze@gabi-soft.de
Need real expertise in C++, Java, OO design
I am available, see my CV at www.gabi-soft.de
Ziegelh=FCttenweg 17a, 60598 Frankfurt, Germany Tel. +49(0)69 63198627
---
[ 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: "DrPizza" <peter@inkvine.fluff.org>
Date: Tue, 28 May 2002 22:51:54 GMT Raw View
Eigil Hysv r <eigil.hysvaer@eudoramail.com> blathered:
> What? Well, 'short' and 'unsigned short' have two different ranges of
> values, but they contain the same amount of possible values. I really
> don't understand what you're taking about !!? Enlighten me :-)
>
Compare, for instance, sizeof(unsigned char) and sizeof(bool). bool has a
range of two values (true and false), unsigned char has a range of
(typically) 256 values (0 - 255). sizeof won't tell you that.
--
peter@inkvine.fluff.org
umop ap!sdn
---
[ 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: "Eigil Hysv r" <eigil.hysvaer@eudoramail.com>
Date: Mon, 27 May 2002 17:38:22 GMT Raw View
"Dag Henriksson" <dag.henriksson@quidsoft.se> wrote in
news:acm2oo$qk9kh$1@ID-107109.news.dfncis.de:
>
> "Francis Glassborow" <francis.glassborow@ntlworld.com> wrote in message
> news:CZJxv2BBdi78EwRR@robinton.demon.co.uk...
>
> It's a common misunderstanding that sizeof can be used to determine the
> range of values that fit in an integral type (except 'unsigned char').
>
What? Well, 'short' and 'unsigned short' have two different ranges of values,
but they contain the same amount of possible values. I really don't
understand what you're taking about !!? Enlighten me :-)
Eigil
---
[ 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: "Edward Diener" <eldiener@earthlink.net>
Date: Tue, 28 May 2002 00:15:09 GMT Raw View
"Eigil Hysv r" <eigil.hysvaer@eudoramail.com> wrote in message
news:Xns921B7AC7218FEeigilhysvaereudorama@194.19.1.61...
> "Dag Henriksson" <dag.henriksson@quidsoft.se> wrote in
> news:acm2oo$qk9kh$1@ID-107109.news.dfncis.de:
>
> >
> > "Francis Glassborow" <francis.glassborow@ntlworld.com> wrote in message
> > news:CZJxv2BBdi78EwRR@robinton.demon.co.uk...
> >
> > It's a common misunderstanding that sizeof can be used to determine the
> > range of values that fit in an integral type (except 'unsigned char').
> >
> What? Well, 'short' and 'unsigned short' have two different ranges of
values,
> but they contain the same amount of possible values. I really don't
> understand what you're taking about !!? Enlighten me :-)
The amount of possible values and the range of possible values are two
different things.
---
[ 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 ]