🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c.moderated
Article #2043

Re: Why Use 'Int' Instead of 'Long'? (With today's compilers)

#2043
From: Gerald Feldman
Date: Sat, 17 Feb 1996 17:54
42 lines
2445 bytes
Andrew Snow wrote:
> 
> wawda@chaph.usc.edu (Abu Wawda) wrote:
> 
> Well, when I learnt C, the following applied:
> 
> If you explicetly wanted a 16 bit data variable, you would use a
> "short int".  If you explicetly wanted a 32 bit variable, you would
> use "long int".  If you didn't mind, and were prepared to use either
> 16-bit or 32-bit, whichever the particular operating system you are
> compiling for decided was best, then you just use "int".
While I do not disagree with your conclusions, as stated by others, the
only thing that you can guarantee is (NON-ANSI):
sizeof(long) >= sizeof(int)>= sizeof(short)>=sizeof(char)
I do know of one popular compiler on Motorola 68000 architectures where
sizeof(short) == 1
In ANSI C (2.2.4.1), 
sizeof(long) >= 4,
sizeof(int) >= 2,
sizeof(short)>=2.
There are described in values, not in bytes, in the standard.

> To make your code completely portable, you should specify long or
> short.  In situations where it really doesn't matter, you can just
> use "int".
The basic assumetion that you should make is that the standard
guarantees certain properties, but it does not guarantee that a long is
32 bits. There are implementations were a long is 36 bits, and a char is
9 bits. Unfortunately, some of these assumtions crawled into much of the
code that makes the Internet work. If you need an integral data type
that is 32 bits, define it using typedefs in a header file. That way,
you can change the header files, and not the rest of the program. IMHO,
any instructor who teaches that a long is 32 bits in C should receive
his/her just deserts. 

[In fact, there is at least one implementation where long is 64 bits,
 and sizeof(long) is 1. -mod]

-- 
Jerry Feldman              Digital Unix Development Environment
Digital Equipment Corp.    Nashua, NH 03062-9987      
gaf@zk3.dec.com, gaf@bcs.org
Technical Details
Message-ID: <4g54nt$aih@solutions.solon.com>
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
References: <4fjk00$nss@solutions.solon.com> <4fu7tj$9a1@solutions.solon.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
From: Gerald Feldman <gaf@zk3.dec.com>
Newsgroups: comp.lang.c.moderated
Subject: Re: Why Use 'Int' Instead of 'Long'? (With today's compilers)
Date: 17 Feb 1996 11:54:05 -0600
Organization: Digital Unix Development Environment
Sender: clc@solutions.solon.com
Approved: clc@solutions.solon.com
Message-ID: <4g54nt$aih@solutions.solon.com>
References: <4fjk00$nss@solutions.solon.com> <4fu7tj$9a1@solutions.solon.com>
NNTP-Posting-Host: solutions.solon.com
X-Mailer: Mozilla 2.0b6a (X11; I; OSF1 T4.0 alpha)