Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 26 Nov 1995 13:52:15 +0100 (MET)
From:      grog@lemis.de (Greg Lehey)
To:        terry@lambert.org (Terry Lambert)
Cc:        hackers@freebsd.org (FreeBSD Hackers)
Subject:   Re: How long is long?
Message-ID:  <199511261252.NAA13345@allegro.lemis.de>
In-Reply-To: <199511241905.MAA10078@phaeton.artisoft.com> from "Terry Lambert" at Nov 24, 95 12:05:45 pm

next in thread | previous in thread | raw e-mail | index | archive | help
Terry Lambert writes:
> 
> > Terry Lambert  <terry@lambert.org> wrote:
> > >That's a bug in the standard in not having mechanisms for obtaining
> > >sized types.  For a 64 bit int (requiring a 64 bit long), short is
> >                                              ^^-- 128
>                                                     ^^^-- 64
> The size of long shall be greater than or equal to the sizeof int.  Your
> 128 says "greater than" and ignores "equal to".
> 
> > >either 16 or 32 bits (undefined) and we lose access to either 32 or
> > >16 bit types (respectively).
> > 
> > What architecture requires a 64 bit (int)?
> 
> Any architecture where 64 bits is the bus transfer size and the registers
> are 64 bits or larger.  It's defined as the "natural type" for the machine.
> 
> But I was assuming a 64 bit int, and it was the int requiring the 64
> bit long, not anything requiring a 64 bit int.
> 
> My complaint is about the long >= int requirement on longs.
> 
> > IMHO, DEC did exactly the right thing making int 32 bits and long 64 bits,
> > given the history of the language, but IMHO the original BSD port to the
> > VAX should have done the same thing, rather than keeping it 32 bits for
> > easier porting of PDP-11 code.
> > 
> > Long doesn't and shouldn't mean "32 bits".
> 
> Maybe not.  But *something* should mean "32 bits".
> 
> The problem is that with a 64 bit int (which, despite your opinion of
> DEC and grandfathering old software, is correct for the Alpha):
> 
> int == 64	:==	long == 64
> short == 32	||	short == 16
> char == 8
> 
> You lose access to either 32 bit or 16 bit sized types.
> 
> Period.

You're looking at this from the wrong perspective.  Even if you say:

> ANSI doesn't allow "long long" or "quad".

That means that ANSI is wrong.  If a language doesn't allow you to
access to the primitive data types of your machine, then it's broken.
In the case of C, the answer is obvious enough.  ANSI doesn't allow
long long, but that doesn't mean you can't use it.  And how about
short short?

I tend to agree with Peter that it's a good idea to keep data sizes
roughly the same.  It may have been a mistake to increase an int from
16 to 32 bits when moving to the Vax, but that's history.  Modern
computers have int lengths which are a power of 2, and that power lies
between 3 and 7 in all cases.  Is it really that difficult to find 5
different descriptions?  For example:

short short   8  bits
short	      16
int	      32
long	      64
long long     128

I don't think that this should be carved in stone; I'd prefer int8,
int16 etc. for things which really *must* be that length (like data
shared with other architectures), but it would make life a lot easier
if people would adhere to the lengths anyway.

Greg



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199511261252.NAA13345>