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=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC 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: fred@genesis.demon.co.uk (Lawrence Kirby) Subject: Re: Porting Experiences (was Ada and Pascal etc ) Date: 1997/11/04 Message-ID: <878648818snz@genesis.demon.co.uk>#1/1 X-Deja-AN: 286967983 References: <345E3ACD.A15@gsg.eds.com> X-Mail2News-User: fred@genesis.demon.co.uk X-Complaints-To: abuse@demon.net X-Mail2News-Path: genesis.demon.co.uk X-Trace: mail2news.demon.co.uk 878654016 29558 fred genesis.demon.co.uk Organization: none Reply-To: fred@genesis.demon.co.uk Newsgroups: comp.lang.ada,comp.lang.c,comp.lang.c++ Date: 1997-11-04T00:00:00+00:00 List-Id: In article <345E3ACD.A15@gsg.eds.com> nospam@gsg.eds.com "Seymour J." writes: >Craig Franck wrote: > >> What is it about Ada that makes it portable? > >How about the ability to define variables by their range instead of >using implimentation-dependent terms like long and short? That's >certainly the most glaring deficiency in C with regard to portability. The portability implications of this are small or non-existent (there may be performace implications in rare circumstances, and issues relating to data sizes and external data formats). 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. 3. If you want to minimise space usage (such as for array elements or structure members) and the range is contained within -32767 to 32767 then you can use short. For -127 to 127 you can use signed char. 4. The unsigned types have larger positive ranges if your range is non-negative. Notably unsigned char typically corresponds to the notion of "byte" in most languages. Stick to the guaranteed minimum ranges guaranteed by the standard and allow for the ranges to be larger and there are no portability issues. This covers the overwhelming majority of cases. C currently doesn't guarantee anything beyond a 32 bit integer type so you will get portability issues if you need something larger. That is a recognised problem that will be addressed in C9X. -- ----------------------------------------- Lawrence Kirby | fred@genesis.demon.co.uk Wilts, England | 70734.126@compuserve.com -----------------------------------------