Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

sizeof int and long on 64bit machines

0 views
Skip to first unread message

Serve Laurijssen

unread,
Feb 10, 2001, 5:44:03 PM2/10/01
to
I am confused.
I was reading the article about converting 32-bit to 64-bit code in the
latest ddj.
The author says that a long is 32 bits on a 32 bit machine (correct), but 64
bit on a 64 bit machine.
int stays the same.
I thought that it was the other way around. Shouldn't an int need to be the
size of a machine word and a long always 32bit? according to Kernighan &
ritchie it has always been like this.

[ Send an empty e-mail to c++-...@netlab.cs.rpi.edu for info ]
[ about comp.lang.c++.moderated. First time posters: do this! ]

Neil Butterworth

unread,
Feb 10, 2001, 7:09:45 PM2/10/01
to
"Serve Laurijssen" <ne...@circe.demon.nl> wrote in message
news:981807570.27845....@news.demon.nl...

> I am confused.
> I was reading the article about converting 32-bit to 64-bit code in the
> latest ddj.
> The author says that a long is 32 bits on a 32 bit machine (correct), but
64
> bit on a 64 bit machine.
> int stays the same.
> I thought that it was the other way around. Shouldn't an int need to be
the
> size of a machine word and a long always 32bit? according to Kernighan &
> ritchie it has always been like this.

Quote to support this please! According to K&R 2nd ed page 257 regarding
<limits.h>

"The values below are acceptable minimum magnitudes; larger values may be
used."

And the relationship has "always" been:

sizeof(int) <= sizeof(long)

NeilB

Francis Glassborow

unread,
Feb 11, 2001, 4:13:43 AM2/11/01
to
In article <981807570.27845....@news.demon.nl>, Serve
Laurijssen <ne...@circe.demon.nl> writes

>I thought that it was the other way around. Shouldn't an int need to be the
>size of a machine word and a long always 32bit? according to Kernighan &
>ritchie it has always been like this.

No, a long int must be at least as wide as an int which must be at least
as wide as a short. A short must be at least 16-bits, and int at least
16 bits and a long 32 bits. But if you choose to have a 64-bit short
then int and long must also be at least 64-bits. I do not think that
K&R says differently but that has nothing to do with C++ anyway.


--
Francis Glassborow
See http://www.accu.org for details of The ACCU Spring Conference, 2001
(includes many regular participants to C & C++ newsgroups)

James Moe

unread,
Feb 11, 2001, 6:25:06 PM2/11/01
to
Serve Laurijssen wrote:
>
> I am confused.
> I was reading the article about converting 32-bit to 64-bit code in the
> latest ddj.
> The author says that a long is 32 bits on a 32 bit machine (correct), but 64
> bit on a 64 bit machine.
> int stays the same.
> I thought that it was the other way around. Shouldn't an int need to be the
> size of a machine word and a long always 32bit? according to Kernighan &
> ritchie it has always been like this.
>
That has (more or less) been the convention. Int normally defaults
to the hardware's integer type. It is a reason the type "long long" is
appearing in various forms to create a 64 bit integer type. Certainly on
16 bit machines sizeof(int) was 16, and sizeof(long) was 32.
Seems I heard of some standards work on defining type sizes
following the lead of Ada and Java. I do not know at what stage it is.

--
sma at sohnen-moe dot com

0 new messages