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: g2news2.google.com!postnews.google.com!k7g2000yqj.googlegroups.com!not-for-mail From: Ludovic Brenta Newsgroups: comp.lang.ada Subject: Re: How do I write directly to a memory address? Date: Tue, 8 Feb 2011 01:08:25 -0800 (PST) Organization: http://groups.google.com Message-ID: <69e4243b-bbcc-4c1d-be07-978496666b4f@k7g2000yqj.googlegroups.com> 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> NNTP-Posting-Host: 153.98.68.197 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1297156105 24460 127.0.0.1 (8 Feb 2011 09:08:25 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 8 Feb 2011 09:08:25 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: k7g2000yqj.googlegroups.com; posting-host=153.98.68.197; posting-account=pcLQNgkAAAD9TrXkhkIgiY6-MDtJjIlC User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.0.6) Gecko/2009012111 Red Hat/3.0.6-1.el5 Firefox/3.0.6,gzip(gfe) Xref: g2news2.google.com comp.lang.ada:17935 Date: 2011-02-08T01:08:25-08:00 List-Id: Nasser M. Abbasi wrote on comp.lang.ada: >> Georg Bauhaus wrote: >>> void foo(int countdown) >>> { >>> =A0 =A0while (--countdown) { >>> =A0 =A0 =A0fputc('.', stdout); >>> =A0 =A0} >>> =A0 =A0fputc('\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? Actually, the bug also triggers if countdown =3D=3D 0 upon entry into foo, because of the *prefix* decrement operator. The behavior is undefined by the language but most C programmers assume that counter will wrap around. In fact, when GCC 4.5 introduced aggressive optimizations based on the knowledge that overflow semantics was undefined in C, a *lot* of existing programs were suddenly broken. In fact, only their incorrect assumptions ("hidden contracts") were broken. The damage was so severe that the GCC folks had to demote this aggressive optimization to a non-default compiler switch :( -- Ludovic Brenta.