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.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,c9d5fc258548b22a X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!feeder.news-service.com!94.75.214.39.MISMATCH!aioe.org!.POSTED!not-for-mail From: "Nasser M. Abbasi" Newsgroups: comp.lang.ada Subject: Re: How do I write directly to a memory address? Date: Tue, 08 Feb 2011 01:01:59 -0800 Organization: Aioe.org NNTP Server Message-ID: References: <67063a5b-f588-45ea-bf22-ca4ba0196ee6@l11g2000yqb.googlegroups.com> <31c357bd-c8dc-4583-a454-86d9c579e5f4@m13g2000yqb.googlegroups.com> <05a3673e-fb97-449c-94ed-1139eb085c32@x1g2000yqb.googlegroups.com> <8r86vgFc3uU1@mid.individual.net> <19fh1chm74f9.11cws0j5bckze.dlg@40tude.net> <4d4ff70e$0$6886$9b4e6d93@newsspool2.arcor-online.net> <737a6396-72bd-4a1e-8895-7d50f287960e@d28g2000yqc.googlegroups.com> <4d5008a5$0$6879$9b4e6d93@newsspool2.arcor-online.net> <4d5031fe$0$6765$9b4e6d93@newsspool3.arcor-online.net> <1f229967-d3cf-42b6-8087-c97ee08652f3@i40g2000yqh.googlegroups.com> Reply-To: nma@12000.org NNTP-Posting-Host: tUYQ4Ty9mMw9Pdc8TJRFQA.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.13) Gecko/20101207 Thunderbird/3.1.7 X-Notice: Filtered by postfilter v. 0.8.2 Xref: g2news1.google.com comp.lang.ada:16963 Date: 2011-02-08T01:01:59-08:00 List-Id: On 2/8/2011 12:04 AM, Ludovic Brenta wrote: > Georg Bauhaus wrote: >>> Well, I came to wonder what intentions are conveyed by "void foo (int >>> arg)" and why modifying arg inside foo could be intentional. Since I >>> came up with no convincing reason (the only reasons being variants of >>> premature optimization), I concluded that the possibility of "void foo >>> (int arg)" as opposed to "void foo (const int arg)" was a flaw in the >>> C language, that cost me a lot of effort. >> >> Ease of implementation when pushing parameters? >> >> void foo(int countdown) >> { >> while (--countdown) { >> fputc('.', stdout); >> } >> fputc('\n', stdout); >> } > > > > BTW, like I said, *every* time I look at C code, This is funny, but I understand what you mean. > I see a bug. In your > case, foo has undefined behavior if countdown is negative. > If I remember my C, since "while" will keep running until its argument becomes false, which in C means "zero", then this means if countdown is negative the above code will keep decrementing countdown until it hits -infinity? :) and the program will crash or do something else? > Also, note how the Ada version of this function does not use a > variable at all; it uses a for loop inside of which K is constant. And > it does not have your bug: > > procedure Foo (Countdown : in Natural) is > begin > for K in 1 .. Countdown loop > Put ('.'); > end loop; > Next_Line; > end Foo; > > So, "ease of implementation" is not a good reason. The thing you > implemented "easily" had a bug. > > -- > Ludovic Brenta. Ada has so many nice things in it. I think its type system is one of the best features of Ada. --Nasser