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=3.9 required=5.0 tests=BAYES_00,INVALID_MSGID, PLING_QUERY,RATWARE_MS_HASH,RATWARE_OUTLOOK_NONAME autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fdb77,4873305131bf4d94 X-Google-Attributes: gidfdb77,public 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: "James S. Rogers" Subject: Re: How big is an int? (was: Yet another stupid language war (was: ... the only languages you need!!)) Date: 1997/11/06 Message-ID: <01bcea71$74603f40$5e20430c@Rogers>#1/1 X-Deja-AN: 287333959 References: <34557f2b.1934172@news.mindspring.com> <345F49A2.5F5DC5A0@aom.ericsson.se> <63oadj$ljc$1@helios.crest.nt.com> <63r09q$q5h$1@helios.crest.nt.com> Organization: AT&T WorldNet Services Newsgroups: comp.lang.ada,comp.lang.c,comp.lang.c++,comp.lang.java.advocacy,comp.lang.c,comp.lang.c++ Date: 1997-11-06T00:00:00+00:00 List-Id: Kaz Kylheku wrote in article > No. What I stated is in the C standard, so it's true for all conforming > implementations. It defines the minimum ranges that all arithmetic types must > have. I wasn't making any claim about the relative sizes of the integral types, > just repeating the minimum range requirements. This is still an interesting answer to the initial question. What you have is not a definition of the size of an int, only a definition of its smallest possible size. So, how big is it, exactly? You have quoted the C standard which in effect says that an int is larger than a bread-box, and even describes the size of a bread-box. From this I can logically, and I believe correctly, assume that a 64 bit int is every bit as conforming as a 32 bit int. The claim has been made that this produces completely portable code. This claim can be supported only if the programmer is prevented from using any int value which cannot be represented by a 32 bit int. Thus, if a system of hardware and compiler uses a 64 bit int, only the first 32 bits can ever be used. If more than the first 32 bits are used the program, although using a conforming compiler, will be completely non-portable to a system using a 32 bit int. What does the C standard say about the behavior of an int at the margin of its ranges? Does 1 + INT_MAX always result in INT_MIN? How about when using an unsigned int? Does 1 + UINT_MAX always result in 0? If not, then what is the portable definition of the behavior of an int at its range limits? Without a well defined set of such conditions no C program could be considered portable for its entire range of int values. Even with such a set of well defined rules, how many C programmers test addition, for instance, to determine that X + 1 is greater than X? Failure to perform such a test can clearly lead to catastrophic behavior at the limits of the range of an int. Your program will then be entirely portable and completely incorrect. Such portability is not a comfort to me. I would rather sacrifice a little portablity for the elimination of such an error. Fortunately, with Ada I do not need to sacrifice either. By explicitly specifying the range of a type I get completely portable results. I also get automatic range checking including the raising of the exception Constraint_Error if a range boundary is violated. I can handle this exception in a non-catastrophic manner without coding in a test at every addition. Thus I can ensure program correctness even under the violation of type range boundaries. This too is entirely portable. Jim Rogers Colorado Springs, Colorado