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,df854b5838c3e14 X-Google-Attributes: gid109fba,public X-Google-Thread: 1014db,df854b5838c3e14 X-Google-Attributes: gid1014db,public X-Google-Thread: 103376,df854b5838c3e14 X-Google-Attributes: gid103376,public From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku) Subject: Re: C/C++ knocks the crap out of Ada Date: 1996/03/15 Message-ID: <4icai1INN608@gambier.ugrad.cs.ubc.ca>#1/1 X-Deja-AN: 142867824 references: <4hm6lo$eln@fred.netinfo.com.au> <4hml8s$a1q@solutions.solon.com> organization: Computer Science, University of B.C., Vancouver, B.C., Canada newsgroups: comp.lang.ada,comp.lang.c,comp.lang.c++ Date: 1996-03-15T00:00:00+00:00 List-Id: In article , Robert A Duff wrote: >In article <4hml8s$a1q@solutions.solon.com>, >Peter Seebach wrote: >>Certainly. A C implementation is free to be an interpreter that emulates >>every bit of every value and checks for arbitrary programming errors. >> >>There is no restriction that an implementation may not offer range checking, >>and many already do have stricter type checking than the standard requires. > >But C doesn't have any syntax for defining the range of an int, except: > > int x; /* x is always between 1 and 10 */ > >So how can a C implementation check this range, without extending the >syntax of the language? There are many other examples. Quite frankly, you can't do it. If the integer is not used as any sort of array index, you don't know what the range is. Here are some alternatives: 1. Use an enumerated type. Drawback: it's not an arithmetic type. Incrementing an enumerated variable, for instance, is a no no. An expression involving an enumerated type promotes it to an int, and can't be assigned back to the enumerated type. 2. assert() macros. This is ugly, and places the burden on the programmer. It does work, however, and _is_ standardized. Specifying ranges for integers is something that I dearly miss about Modula 2. (But that's about it...) It really is a significant feature. --