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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1108a1,59ec73856b699922 X-Google-Attributes: gid1108a1,public X-Google-Thread: 103376,583275b6950bf4e6 X-Google-Attributes: gid103376,public X-Google-Thread: 11232c,59ec73856b699922 X-Google-Attributes: gid11232c,public X-Google-Thread: fdb77,5f529c91be2ac930 X-Google-Attributes: gidfdb77,public X-Google-ArrivalTime: 2003-05-11 17:47:19 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!arclight.uoregon.edu!wn13feed!wn12feed!worldnet.att.net!bgtnsc05-news.ops.worldnet.att.net.POSTED!not-for-mail From: Dave Thompson Newsgroups: comp.lang.java.advocacy,comp.object,comp.lang.ada,misc.misc Subject: Re: Using Ada for device drivers? (Was: the Ada mandate, and why it collapsed and died) Message-ID: <1mrtbv48hufvmmk69gd60v7fm4csoks0nh@4ax.com> References: <9fa75d42.0305010621.55e99deb@posting.google.com> <254c16a.0305011035.13133e8d@posting.google.com> <9fa75d42.0305011727.5eae0222@posting.google.com> <17cd177c.0305072114.24f04783@posting.google.com> <9fa75d42.0305090612.261d5a5c@posting.google.com> <82347202.0305091052.d8161a4@posting.google.com> X-Newsreader: Forte Agent 1.93/32.576 English (American) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Mon, 12 May 2003 00:47:19 GMT NNTP-Posting-Host: 12.89.64.224 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc05-news.ops.worldnet.att.net 1052700439 12.89.64.224 (Mon, 12 May 2003 00:47:19 GMT) NNTP-Posting-Date: Mon, 12 May 2003 00:47:19 GMT Organization: AT&T Worldnet Xref: archiver1.google.com comp.lang.java.advocacy:63540 comp.object:63219 comp.lang.ada:37213 misc.misc:14094 Date: 2003-05-12T00:47:19+00:00 List-Id: On 9 May 2003 11:52:31 -0700, jimmaureenrogers@worldnet.att.net (Jim Rogers) wrote: [snip] > The most convenient feature when dealing with arrays is > Ada's ability to efficiently deal with array bounds > checking. > > For example, if I define an Ada string with a length > of 10 characters: > > Name : String(1..10); > > I can then perform I/O using that string object and > never need to worry about array bounds violations. > > Ada.Text_Io.Get_Line(Item => Name, Last => Count); [snip] > In C I would need to do something like the following: > char name[11]; > > scanf("%.10s", name); > Not quite. Ada Get_Line is much closer to C fgets, although it does store the newline character (if it fits) and you must often deal with removing it, and it does not return the length explicitly (you must strlen for it). > The point here is that I must hardcode the size limit > into the scanf format string. If I change the size of > the array then I must also change the scanf format > string. > For fgets the length is a separate argument and so can and almost always should be computed as sizeof(buf) without hardcoding *if* buf is local or global, but not if passed as a parameter/dummy/formal because C doesn't have true array parameters only pointers that don't carry size information. *scanf %s reads only up to whitespace, not a whole line, making it more like a nonstandard Get_Token. Even if you make it %limit[^\n] (any characters except newline) it doesn't 'eat' the newline, and just adding a %*c in the same call won't work if the %[ read nothing (failed). You can in simple cases hack in a #define'd length using preprocessor stringize (and string literal concatenation) or in general compute the format string at runtime, but neither is as convenient as even passing the bound explicitly to fgets, much less automatically as in Ada. > Unfortunately, array bounds violations are still a common > failure mode in C programs. The techniques for avoiding > array bounds violations are well known. Unfortunately > they are not used as frequently as one would like. > Concur, and with the rest [snipped]. - David.Thompson1 at worldnet.att.net