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,FREEMAIL_FROM autolearn=ham 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-7-bit Path: g2news1.google.com!news1.google.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!nx02.iad01.newshosting.com!newshosting.com!198.186.194.249.MISMATCH!transit3.readnews.com!transit4.readnews.com!news-out.readnews.com!postnews7.readnews.com!not-for-mail Date: Tue, 08 Feb 2011 10:36:23 -0500 From: Hyman Rosen User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.13) Gecko/20101207 Thunderbird/3.1.7 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: How do I write directly to a memory address? 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> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <4d516394$0$29394$882e7ee2@usenet-news.net> NNTP-Posting-Host: c07eca82.usenet-news.net X-Trace: DXC=i4jLN]j>2N3gHd:E^O84G9QFZ3T]GPM]7mX0AG3X_jU?7J]G7Of^W10VjKk:Lk^BN1cR12TN^Bg7>i6QJ9?:Y@R2f0D92_G=fB1 X-Complaints-To: abuse@usenet-news.net Xref: g2news1.google.com comp.lang.ada:16996 Date: 2011-02-08T10:36:23-05:00 List-Id: On 2/7/2011 4:00 AM, Ludovic Brenta wrote: > I recently found another bug in a C program that was caused > by changing the value of a "passed-by-copy" parameter. Of > course the caller was unaffected but the algorithm inside > the function was broken. In C or C++, a function parameter is an ordinary variable which is initialized by the an expression in the function call. If the parameter is not const, it may then be changed during the operation of the function. C has worked this way for something like forty years, so being surprised by this now seems disingenuous. There's no particular reason that a function parameter should not be permitted to be changed, notwithstanding that you found a case where doing so caused an error. One puts implementation, for example, is int puts(char *s) { while (*s) if (putchar(*s++) == EOF) return EOF; return putchar('\n'); } and a C programmer would be puzzled when told that this function would be better if he had to use another variable initialized to the value of 's' before getting down to business. I rather think that it's Ada that got it wrong here, by choosing to combine the concept of passing by value or reference and the concept of immutability. Evidence for that is the fact that in several places the Ada standard has to say that a parameter must be passed by reference while the declaration of the subprogram does not give you that information (because the parameter is 'in').