|
From: Joerg B. <jo...@sq...> - 2001-04-09 08:48:21
|
Hi !
Lloyd Dupont wrote:
>
> ok, if i well understand char, short, long have a size independant
> of thet processor
> whire are, respectively, 1, 2, 4.
> and int is the size of a register. 4 on 486 machine an even 8 on a
> 64 bits machine (so sinzeof(int) > sizeof(long) for such a machine)
I do not know the exact location(s) in the C standard(s),
but I am quite sure this is wrong:
On byte-addressable machines, "char" is 1 byte.
(AFAIK, it is even defined that on _all_ machines
sizeof ( char ) == 1 .)
On all machines, the C standard(s) require
sizeof ( short ) <= sizeof ( int ) <= sizeof ( long )
and corresponding (take "(=" to read "is a subset of" / "is contained
in")
(set of all "short" values) (= (set of all "int" values)
(= (set of all "long" values)
(the same for the "unsigned" variants).
Now these two properties would be violated by your assumption.
If sizeof(long) < sizeof(int) ever were true, you could have
"int" values which do not fit into a "long" variable, this might
break several programs IMHO.
AFAIK, typically sizeof ( short ) == 2
and (on 16- or 32-bit hardware) sizeof ( long ) == 4
on 16-bit-hardware sizeof ( int ) == 2
whereas on 32-bit-hardware sizeof ( int ) == 4
On 64-bit-hardware, there may be several cases:
a) sizeof ( int ) == 4 sizeof ( long ) == 8
if the system was designed as 64-bit from the start
(like the Alpha by Digital, now Compaq)
b) sizeof ( int ) == 4 sizeof ( long long ) == 8
(at least IBM's POWER had that new type "long long"
in the C compilers for AIX versions 4.1 and 4.2,
to overcome the 2 GB file size limit even on 32-bit HW)
sizeof ( long ) == 4 ???
if binary compatibility with older hw versions is an issue
(IBM's POWER going from 32-bit to 64-bit, same may hold for HP)
(Disclaimer: I am not sure about "long" here, please check!)
Regards,
Joerg Bruehe
--
Joerg Bruehe, SQL Datenbanksysteme GmbH, Berlin, Germany
(speaking only for himself)
mailto: jo...@sq...
|