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-Thread: a07f3367d7,c9d5fc258548b22a X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!postnews.google.com!n36g2000pre.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: How do I write directly to a memory address? Date: Tue, 8 Feb 2011 08:44:40 -0800 (PST) Organization: http://groups.google.com 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> <4d516394$0$29394$882e7ee2@usenet-news.net> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1297183481 30725 127.0.0.1 (8 Feb 2011 16:44:41 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 8 Feb 2011 16:44:41 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: n36g2000pre.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618; .NET4.0C),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:16998 Date: 2011-02-08T08:44:40-08:00 List-Id: On Feb 8, 7:36=A0am, Hyman Rosen wrote: > 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 > > =A0> course the caller was unaffected but the algorithm inside > =A0> 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 > > =A0 =A0 =A0int puts(char *s) > =A0 =A0 =A0{ > =A0 =A0 =A0 =A0 =A0while (*s) if (putchar(*s++) =3D=3D EOF) return EOF; > =A0 =A0 =A0 =A0 =A0return putchar('\n'); > =A0 =A0 =A0} But if C has been working this way for forty years, and its programmers still can't get it right (as evidenced by the fact that Ludovic found a bug), then it's arguable that the language is making it too easy to write incorrect code and too difficult to write code you can count on. A two-line example such as yours doesn't count as evidence against that; it's easy to get really short subroutines correct. The problems come up when you have larger routines. And I've run into this problem with a program I maintain, in a language (not C) that also allows value parameters to be modified locally. Someone has gone into it and written a statement that uses the parameter, assuming that it's the value that the caller gave it, without realizing that someone else had written a statement up above that changed the parameter's value. There's always going to be a religious war between those who want a language that doesn't make them do extra annoying stuff and putting annoying restrictions on their code, and those who prefer a language that provides some degree of protection against stupid errors (not only their own, but stupid errors made by the other programmer down the hall who got laid off two years ago). I'm certainly not going to resolve the religious war here. But since I do so much of my work with other people's code, I do have a preference for the latter, and I think Ada got this one right. -- Adam