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.2 required=5.0 tests=BAYES_00,INVALID_MSGID, PLING_QUERY autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1014db,4873305131bf4d94 X-Google-Attributes: gid1014db,public X-Google-Thread: fdb77,4873305131bf4d94 X-Google-Attributes: gidfdb77,public X-Google-Thread: 103376,4873305131bf4d94 X-Google-Attributes: gid103376,public X-Google-Thread: 109fba,4873305131bf4d94 X-Google-Attributes: gid109fba,public From: Corey Minyard Subject: Re: How big is an int? (was: Yet another stupid language war (was: ... the only languages you need!!)) Date: 1997/11/05 Message-ID: #1/1 X-Deja-AN: 287117764 Sender: minyard@wf-rch.cirr.com References: <34557f2b.1934172@news.mindspring.com> <3456e71b.3833189@news.mindspring.com> <3458D116.2D34@pseserv3.fw.hac.com> <63anc7$75p$1@darla.visi.com> <345947D2.D20EF8E9@horvath.com> <345F49A2.5F5DC5A0@aom.ericsson.se> <345f4f9e.0@isc-newsserver.isc.rit.edu> <34666a87.96408197@pncnt.tecnomen.ie> Organization: Wonderforce Research Newsgroups: comp.lang.ada,comp.lang.c,comp.lang.c++,comp.lang.java.advocacy,comp.lang.c,comp.lang.c++ Date: 1997-11-05T00:00:00+00:00 List-Id: mark@$tecnomen$.ie (Mark Burkley) writes: > > dwa1844@rit.edu (Daniel Anderson) wrote: > > >In article <345F49A2.5F5DC5A0@aom.ericsson.se>, qhslyng@aom.ericsson.se says... > >> > >>Bob Horvath wrote: > >>> > >>> Hmmmm. How big is an int? > >> > >>As I've understood it, an int has two legal sizes. A short has only one, > >>and the same goes for a long. I believe that there were a lot of > >>different compilers on the market before C was standardised. Some used 2 > >>byte int and some used 4 byte ints. > >> > >>short = 2 bytes > >>int = 2 or 4 bytes > >>long = 4 bytes > >> > >>If this is true, I see no reason for ever using ints in new C programs. > > It's not true. int is *normally* the register size of the machine you > are using. If you are using a 64-bit platform, an int will probably > be 8 bytes. A long must be at least as long as this. In this case, > it would be quite reasonable to have a 4 byte short. > > Of course, the standard says it can be any size you like so long as an > int is at least as long as a short and a long is as least as long as > an int and they are all meet the minimum sizes. AFAIK, they could > legitimately be all the same size. > > >Actually, the size of the variables (the byte sizes) depend on the operating > >system. > > More usually, it depends on the CPU. > I can strongly validate this. I have used C on a TMS320C30 and TMS320C40 (fine DSPs for the job I was doing). On that platform, EVERYTHING is 32-bits. char, short, int, long, float, and double. sizeof() would return 1. The DSP could only address 32-bit quantities. I managed to write portable code (the shared memory buffer pipe code between the DSP and host used exactly the same code on each side) but it took great care. You can write portable low-level C code if you do it very carefully and are willing to put up with some messiness with macros and some header files that require porting between platforms. Writing high-level portable C would be easy if all OS's include files were in the same place and everyone was careful about data ranges. Unfortunately, that is not the case. I think Ada is where this thread all started. It is easier to write portable low-level Ada code because of the precise sizing, alignment and layout facilities it provides. It still requires care, though, but it is a lot cleaner, more clear, and easier to maintain. I have written many hundreds of thousands of lines of C code and maybe 50,000 lines of Ada code. I personally prefer Ada because it lets me be in complete control of what is happenning while still abstracting things to a higher level. It is not a silver bullet and it takes some learning and discipline to use Ada well. However, I don't want to go back. I might have to, though, because IMHO the biggest problem with Ada is getting it on the needed target platforms. My boss gave me the news I was dreading, if we can't get an Ada compiler we can afford for our target we are probably porting the code I have written to C. I guess I've rambled on enough. Sorry, but I thought the int size needed some validation. -- Corey Minyard Internet: minyard@acm.org Work: minyard@nortel.ca UUCP: minyard@wf-rch.cirr.com