From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 109fba,4873305131bf4d94 X-Google-Attributes: gid109fba,public X-Google-Thread: 1014db,4873305131bf4d94 X-Google-Attributes: gid1014db,public X-Google-Thread: 103376,4873305131bf4d94 X-Google-Attributes: gid103376,public From: scs@eskimo.com (Steve Summit) Subject: Re: Porting Experiences (was Ada and Pascal etc ) Date: 1997/11/05 Message-ID: <63q68a$68c$1@eskinews.eskimo.com>#1/1 X-Deja-AN: 287216289 References: <345E3ACD.A15@gsg.eds.com> <878648818snz@genesis.demon.co.uk> <345F9728.D61@gsg.eds.com> Followup-To: comp.lang.c,comp.lang.c++ Organization: better late than never Newsgroups: comp.lang.ada,comp.lang.c,comp.lang.c++ Date: 1997-11-05T00:00:00+00:00 List-Id: [followups trimmed slightly] In article <345F9728.D61@gsg.eds.com>, nospam@gsg.eds.com writes: > Lawrence Kirby wrote: >> As ever the C language is designed >> with the assumption that the programmer knows what he is doing. The use >> of ranges implies that you know beforehand what those ranges will be. >> In C you follow a set of rules: >> 1. If the range is contained within -32767 to 32767 then you use int >> 2. If the range is contained within -2147483647 to 2147483647 then you >> use long. >>... > > Those rules only apply if you are going from one 32-bit machine to > another; they have nothing to do with the definition of C itself and are > inapplicable when you have to move between different word sizes. What on earth are you talking about? The rules Lawrence cited (including the two I snipped) are taken *directly* from "the definition of C itself", both the original K&R definition and the modern ANSI/ISO definition. > The C standard makes the size of an int implimentation dependent... Correct. > and on > 16-bit machines it is normally 16. On 64-bit machines int is usually 64, > and if you want 32 you specify short. And on both of those machines, a program that attempted to store numbers in the range +-32767 in ints or short ints would work without change. If you write C programs that "want" ints of certain sizes, such as 16 or 32 bits, you will have portability headaches 'til the end of your days. If you write programs that assume that types int and short int have a range of +-32767, and that long int has a range of +-2147483647, your programs will work under every C compiler everywhere, including compilers you've never heard of, or that haven't been written yet, for machines that haven't been built or even dreamed of yet, including those with 17-bit short ints and 23-bit ints and 41-bit long ints. *That's* portability. Rewriting your program or adjusting all its typedefs every time you port it to a new machine is an exercise in futility. Steve Summit scs@eskimo.com