Article View: comp.lang.c.moderated
Article #2006Re: Why Use 'Int' Instead of 'Long'? (With today's compilers)
From: Dan Pop
Date: Fri, 16 Feb 1996 06:07
Date: Fri, 16 Feb 1996 06:07
36 lines
2016 bytes
2016 bytes
In <4fu7tj$9a1@solutions.solon.com> als@fl.net.au (Andrew Snow) writes: >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". Then, you learned C when there was only one implementation available: the original Ritchie compiler for PDP-11. Soon after that, C was implemented on a platform with 9/18/36-bit integer types. This is mentioned in K&R1, with the purpose to show that assumptions on the sizes of various types (and on the signedness of char) are unsafe. >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". Operating systems don't make such decisions. Compiler implementors do. Both 16 and 32-bit compilers are available for MSDOS/Windows. >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". To make your code completely portable you shouldn't rely on more than 16 bits for short and int and on more than 32 bits for long. If your code breaks because a short is 64 bits (such implementations do exist) it's entirely your fault. Dan -- Dan Pop CERN, CN Division Email: danpop@mail.cern.ch Mail: CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
Technical Details
Message-ID:
<4g16ul$mnu@solutions.solon.com>Path:
arc1-ca.pugleaf.net!solon.com!not-for-mailReferences:
<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: danpop@mail.cern.ch (Dan Pop) Newsgroups: comp.lang.c.moderated Subject: Re: Why Use 'Int' Instead of 'Long'? (With today's compilers) Date: 16 Feb 1996 00:07:17 -0600 Organization: CERN European Lab for Particle Physics Sender: clc@solutions.solon.com Approved: clc@solutions.solon.com Message-ID: <4g16ul$mnu@solutions.solon.com> References: <4fjk00$nss@solutions.solon.com> <4fu7tj$9a1@solutions.solon.com> NNTP-Posting-Host: solutions.solon.com X-Newsreader: NN version 6.5.0 #7 (NOV)