delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1998/07/24/04:35:40

From: Tim DOT Writer AT ftlsol DOT com (Timothy Writer)
Subject: Re: long long vs long
24 Jul 1998 04:35:40 -0700 :
Message-ID: <m3emvcmpb3.fsf.cygnus.gnu-win32@snoopy.ftlsol.com>
References: <199807221508 DOT LAA12504 AT alcove DOT wittsend DOT com>
Mime-Version: 1.0 (generated by tm-edit 7.108)
To: "Michael H. Warfield" <mhw AT alcove DOT wittsend DOT com>
Cc: GMurray AT cware DOT co DOT uk (Graham Murray), gnu-win32 AT cygnus DOT com

"Michael H. Warfield" <mhw AT alcove DOT wittsend DOT com> writes:

> Graham Murray enscribed thusly:
> > This is probably a silly question, but rather than having long long for
> > 64 bit, why was long not made 64bit? The standard (AFAIK) states that
> > short <= int <= long.  So, it should be possible for long to be 64 bit
> > rather than 32. This would give a simple progression from 8bit chars to
> > 64bit longs.
> 
> 	Unfortunately the standard also specifies the length of several
> types.  Specifically char is 8 bits, short is 16 bits, and long is 32 bits.

The standard says no such thing.  In section 5.2.4.2.1 Sizes of integral
types <limits.h>, it says

        The values given below shall be replaced by constant expressions
    suitable for use in #if preprocessing directives....  Their
    implementation defined values shall be EQUAL or GREATER [emphasis
    mine] in magnitude (absolute value) to those shown, with the same
    sign.

    -- number of bits for smallest object that is not a bit field (byte)
       CHAR_BIT				8

    ....

    -- minimum value for an object of type short int
       SHRT_MIN			   -32767

    -- maximum value for an object of type short int
       SHRT_MAX			   +32767

    ....

    -- minimum value for an object of type int
       INT_MIN			   -32767

    -- maximum value for an object of type int
       INT_MAX			   +32767
  
    ....

    -- minimum value for an object of type long int
       LONG_MIN		      -2147483647

    -- maximum value for an object of type long int
       LONG_MAX		      +2147483647

The first paragraph clearly states that these values are implementation
defined and that the sample values are suitable minimums.

Furthermore, in section 6.1.2.5 the Standard states, "There are four signed
integer types, designated as signed char, short int, int, and long int."  It
then goes on to say, "In the list of signed integer types above, the range of 
values of each type is a subrange of the values of the next type in the
list."

In other words,

    sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long)

and

    sizeof(char)  == 1
    sizeof(short) >= 2
    sizeof(int)   >= 2
    sizeof(long)  >= 4

While I agree that there is a large body of code that assumes long is 32
bits, such code is not portable.  And not because of a flaw in the Standard,
but because the programmer(s) responsible either didn't know the above or
didn't care.

-- 
Tim Writer                                              Tim DOT Writer AT ftlsol DOT com
FTL Solutions Inc.
Toronto, Ontario, CANADA
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019