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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,c9d5fc258548b22a X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!n16g2000prc.googlegroups.com!not-for-mail From: Shark8 Newsgroups: comp.lang.ada Subject: Re: How do I write directly to a memory address? Date: Wed, 9 Feb 2011 16:16:48 -0800 (PST) Organization: http://groups.google.com Message-ID: <86a277d4-d0a2-428a-aee2-1f8ac159cf76@n16g2000prc.googlegroups.com> References: <67063a5b-f588-45ea-bf22-ca4ba0196ee6@l11g2000yqb.googlegroups.com> <4d52b489$0$19486$882e7ee2@usenet-news.net> <9a8njlwvey1p.1a96yvvgdf6yu.dlg@40tude.net> <4d52c5e5$0$19486$882e7ee2@usenet-news.net> <720b7e8f-1ae2-4b3b-851e-12b08b3c99e0@r4g2000prm.googlegroups.com> <4d52dd97$0$18057$882e7ee2@usenet-news.net> <9a8f406d-05ca-4bf3-8487-918d4e0dd634@o18g2000prh.googlegroups.com> <4d52ee47$0$18057$882e7ee2@usenet-news.net> <4d5306a0$0$18057$882e7ee2@usenet-news.net> <76c123ab-7425-44d8-b26d-b2b41a9aa42b@o7g2000prn.googlegroups.com> <4d5310ab$0$18057$882e7ee2@usenet-news.net> <9bff52ca-6213-41da-8fa4-3a4cdd8086d3@y36g2000pra.googlegroups.com> <4d5315c8$0$18057$882e7ee2@usenet-news.net> <4d531a54$0$18057$882e7ee2@usenet-news.net> NNTP-Posting-Host: 174.28.151.164 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1297297008 31860 127.0.0.1 (10 Feb 2011 00:16:48 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 10 Feb 2011 00:16:48 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: n16g2000prc.googlegroups.com; posting-host=174.28.151.164; posting-account=lJ3JNwoAAAAQfH3VV9vttJLkThaxtTfC User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13 ( .NET CLR 3.5.30729; .NET4.0E),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:18163 Date: 2011-02-09T16:16:48-08:00 List-Id: On Feb 9, 3:50=A0pm, Hyman Rosen wrote: > On 2/9/2011 5:38 PM, Vinzent Hoefler wrote: > > OK, I know I'm sounding like a smart ass, but take my > question seriously. There's an awful lot of castigation > of C code (and coders) going on here, with complaints > about "bugs on every line", but isn't that equally true > of Ada code? No, there are some errors in C that are flatly impossible within Ada; one of my 'favorite' being the ability to put an assignment int a conditional-test. I realize that there are *SOME* possibly valid uses thereof, but in my experience the overwhelming majority of the time it's encountered it is the incorrect formulation of a condition-test and needs/needed to be corrected. The reduction of *possible* errors necessarily means that the purely-random chance of producing an error-free program is increased. > Doesn't every subprogram call potentially > raise Storage_Error, and isn't that possibility usually > ignored? No, and no. First, consider this: Procedure main is Procedure Stub is begin null end Stub; begin Stub; end main; Where main is anagolus to C's main... unless you truly ARE out of memory, in which case the program-loader should itself give you the error, there is enough memory for Stub because there was enough for main, which was loaded and Stub is a part of main. {There could be odd-compiler exceptions where this isn't true.} Furthermore even though it is a general possibility that any subprogram could raise storage_error, this is *NOT* generally unaccounted for, the program halts and displays just that error. IE - In just the way that JAVA cannot triple-fault your system with an un-handled exception because the JAVA-VM program has a handler built-in to a) display the error and b) prevent the exception from cascading into the OS, so to is the exception system in Ada; instead of merrily chugging away the proper message is displayed and thins are 'shut down' to save the rest of the system. > And in fact, don't Ada newbies run into this > all the time, because they declare large arrays or > records as local variables and run out the call stack? That's an interesting question... it is an honest way to handle something, arrays in particular, to throw out a message saying "I don't have enough memory to do this!" and halt the program, than say pretending that doesn't matter and allowing the program to continue, no? That beginners make the mistake of over-allocating memory is not, in my thinking, a very valid complaint. If you're coming in from a heavy math-background then the limitations {like the finiteness of integer-types, or the [im]precision of floating types} is certainly bothersome, but accurately reflect the limitations of the underlying hardware. {Some languages, like Prolog, have no real limit to the range of representable integers except ALL OF MEMORY.} On the other hand, someone coming in to CS from, say, high- school would encounter the exact same problem of limitations but with the added burdens of ignorance regarding, say, the properties of numbers. Ada offers the BEST combination I have seen between showing the finite/limited nature of the computer, allowing/encouraging the use of properties (sub-types like Natural & Positive), and expressing it all in a high-level manner. Java, as a counter-example strives to express things as "Objects," in a high-level uniform manner with abstraction and methods and all that, but low-level {device-driver} it is not. C (note I am not saying C++) is at the opposite end of the spectrum where it focuses endlessly on the limitations of the hardware w/o providing much in the way of abstraction: functions. C's "arrays" are an interesting result of this; they really aren't arrays, just pointers and the item in the [] is an offset, and in C-compilers {at least one} you could say 4[array] instead of array[4] because that specific array- element IS accessible as Array_base_Address + 4 and the '+' is the same regardless of which side is which. LISP, on the other-other hand is a sort of high-level emphasize- the-properties type. Many mathematical functions are a fairly straightforward translation, though the prefix-syntax is a bit odd. As you can see the Fibonacci function[s] are a straightforward translation of the math piecewise-function: (defun fib (0) 1) (defun fib (1) 1) (defun fib (n) (+ (fib (- n 1)) (fib (- n 2))) ) In this manner, LISP is almost the polar opposite of C; it is utterly unconcerned about the interior-implementation and underlying hardware. If "newbies can easily create a whole memory-sized array" is really that much of a problem, then LISP would be the answer.