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: 11232c,59ec73856b699922 X-Google-Attributes: gid11232c,public X-Google-Thread: fdb77,5f529c91be2ac930 X-Google-Attributes: gidfdb77,public X-Google-Thread: 103376,583275b6950bf4e6 X-Google-Attributes: gid103376,public X-Google-Thread: 1108a1,59ec73856b699922 X-Google-Attributes: gid1108a1,public X-Google-ArrivalTime: 2003-05-13 20:25:05 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!arclight.uoregon.edu!wn13feed!worldnet.att.net!204.127.198.203!attbi_feed3!attbi.com!rwcrnsc54.POSTED!not-for-mail Message-ID: <3EC1B704.1070207@attbi.com> From: "Robert I. Eachus" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.2) Gecko/20021120 Netscape/7.01 X-Accept-Language: en-us, en MIME-Version: 1.0 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) 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> <1mrtbv48hufvmmk69gd60v7fm4csoks0nh@4ax.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 24.62.164.137 X-Complaints-To: abuse@attbi.com X-Trace: rwcrnsc54 1052882703 24.62.164.137 (Wed, 14 May 2003 03:25:03 GMT) NNTP-Posting-Date: Wed, 14 May 2003 03:25:03 GMT Organization: AT&T Broadband Date: Wed, 14 May 2003 03:25:03 GMT Xref: archiver1.google.com comp.lang.java.advocacy:63728 comp.object:63338 comp.lang.ada:37308 misc.misc:14145 Date: 2003-05-14T03:25:03+00:00 List-Id: Dave Thompson wrote: > 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). There are three errors here. The first is a category error. The description of Ada.Text_IO.Get was just to show that in Ada, you can never have a buffer overflow error. (Unless of course you go very far out of your way to specifically program one. It can be done, but many Ada programmer don't know how, and most Ada programmers would consider going out of your way to construct an Ada program that had a potential buffer overflow not as a challenge, but as a kind of pornography. The second error is technical. If an Ada program copies a newline character as part of a Get, that is an error. If the type of the text file was incorrectly specified, for example as one where LF (linefeed) is the representation of end of line, instead of CR LF, then you will read a CR character. This occasionally used to happen when people ported files between Windows and Unix. I think now thought that all Ada compilers accept any combination of CR and LF as end of line, while using the appropriate end of line marker for that system when writing text files. Finally, in Ada the only cases where you need to call strlen is when converting a C or C++ string to an Ada String. In Ada the name of the length of the string named Foo is Foo'Length. But it is an explict property of the string, just like Foo'First and Foo'Last. (Most Ada compilers only store two of the three attributes as part of the representation of a dynamic string. (A string whose length is not known at compile time.) But that is an implementation detail. The whole point here is that an Ada programmer never worries about the length of a string or the any of the implicit checking that needs to be explicit in C. In fact in Ada 95 there are several library packages defined to make it easier to create string objects with different properties. The objects of the standard String type have their attributes determined when the object is created. The values of the String type can be of any size or bounds. (Well subject to X'Last-X'First+1 = X'Length.) However there is an explicit type Ada.Strings.Unbounded.Unbounded_String, which can store different length strings. (Yes, you can rename it if you want to use it. ;-) This is handy if you want to create "ragged" arrays of strings, or to have a library level string object whose length changes. There is also a Bounded_String type which corresponds to the PL/I char * varying, or what most C programmers thing that buffers are like. (But assigning to long a string to a Bounded_String will cause an error. If you don't know what the limit should be, or can't figure out how to handle the exception, use Unbounded_String instead.)