Re: Natural size: int
- From: "Stephen Sprunk" <stephen@xxxxxxxxxx>
- Date: Tue, 8 Aug 2006 15:55:27 -0500
"Frederick Gotham" <fgothamNO@xxxxxxxx> wrote in message
news:fk6Cg.12408$j7.321473@xxxxxxxxxxxxxxxxx
Stephen Sprunk posted:
Or perhaps should "short" be 32-Bit? Or should "char" become
16-Bit
(i.e. 16 == CHAR_BIT).
A char should be the smallest addressable unit of memory; if your
system only supports 16-bit (or greater) loads, it may be
reasonable
to have CHAR_BIT==16, but expect to have to hack up virtually every
program you try to port. Even Cray and the DEC Alpha had to
synthesize 8-bit loads for the char type, because not doing so was
suicide.
I don't see why (unless you're reading/writing data to/from disk
perhaps?).
Another semi-related question:
If we have a variable which shall store the quantity of
elements
in an
array, then should we use "size_t"? On a system where "size_t"
maps
to "long unsigned" rather than "int unsigned", it would seem to be
inefficient most of the time.
You assume that shorter ints are somehow more efficient than longer
ints; many modern processors have slow shorts and int is no faster
than long or long long.
No, I presume that int is faster than long (or they're both as fast
as each
other).
I would expect the following:
speed_of(int) >= speed_of(long)
True in every implementation I've seen; int is typically chosen to be
the fastest size that the platform supports (of at least 16 bits).
However, there is no guarantee that the designers of a particular
implementation possess common sense.
speed_of(int) >= speed_of(short) >= speed_of(char)
Not always true. shorts are slower than chars even on some common
platforms (e.g. Intel P6-based cores), and chars may be faster than
ints and shorts due to reduced memory pressure.
I would expect ints to be faster than shorts or chars in most
situations, but it's possible that memory effects may make chars
faster for particular tasks.
S
--
Stephen Sprunk "God does not play dice." --Albert Einstein
CCIE #3723 "God is an inveterate gambler, and He throws the
K5SSS dice at every possible opportunity." --Stephen Hawking
--
Posted via a free Usenet account from http://www.teranews.com
.
- References:
- Natural size: int
- From: Frederick Gotham
- Re: Natural size: int
- From: Stephen Sprunk
- Re: Natural size: int
- From: Frederick Gotham
- Natural size: int
- Prev by Date: Re: long double versions of functions in gcc under Cygwin
- Next by Date: Re: what is size of this macro?
- Previous by thread: Re: Natural size: int
- Next by thread: Re: Natural size: int
- Index(es):
Relevant Pages
|