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: 103376,c9d5fc258548b22a X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!feeder.news-service.com!85.214.198.2.MISMATCH!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Simon Clubley Newsgroups: comp.lang.ada Subject: Re: How do I write directly to a memory address? Date: Mon, 7 Feb 2011 12:31:29 +0000 (UTC) Organization: A noiseless patient Spider 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> <5d9bd120-4953-4fb1-a890-27267245e954@8g2000prt.googlegroups.com> <883b7161-15ee-4874-95bb-2e0273dab51d@y36g2000pra.googlegroups.com> <8r9iboFkfvU1@mid.individual.net> <14246472-9488-488a-8720-77b85b91707c@d23g2000prj.googlegroups.com> <8r9ouqFselU1@mid.individual.net> Injection-Date: Mon, 7 Feb 2011 12:31:29 +0000 (UTC) Injection-Info: mx01.eternal-september.org; posting-host="4pjzwDT2MPp9AkNxUo/C4Q"; logging-data="10768"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19hMsHrxC/UDuRrw8G+c+Nr3m0Pr2/3+R4=" User-Agent: slrn/0.9.8.1 (VMS/Multinet) Cancel-Lock: sha1:+PFfnwZesy5SmTClpmnKFfIn+Ts= Xref: g2news1.google.com comp.lang.ada:16923 Date: 2011-02-07T12:31:29+00:00 List-Id: On 2011-02-07, Niklas Holsti wrote: > Shark8 wrote: >> *In some languages a "constant" [rather literal] was a label/pointer >> to the location which held the value thereof and one could therefore >> "change the value of '4'" with some dirty-tricks/black-magic. > > A former colleague of mine spent a considerable time debugging a FORTRAN > IV program's wrong results before he found that a COMMON area contained, > in order, a one-dimensional array and a variable that was supposed to > hold the value of pi, as set up at program start. An assignment to the > array with an index that was too large had changed "pi" to something > else, with unfortunate consequences for later trigonometric calculations. > > Unless your Ada program uses hardware (MMU) protection for its > memory-resident constants you can change the "constants" through > accesses that you get from address-to-access conversions. > I think the "change the value of 4" reference above is literally that and does not mean changing a language accessible constant containing the value of 4. I made this mistake once with a old Fortran compiler when I was a student. The constant would be placed into a memory location somewhere by the Fortran compiler and then that memory location would be referenced at every point in the code in which the literal value (the integer 4 in this example) was used in a expression or a call to a subroutine. In my case, I assigned (IIRC) to the calling argument within the subroutine and the memory location containing the literal value (in this example, 4) was changed. This meant that the value of 4 was changed for the rest of the program. I did not make this mistake a second time. :-) Simon. -- Simon Clubley, clubley@remove_me.eisner.decus.org-Earth.UFP Microsoft: Bringing you 1980s technology to a 21st century world