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-7-bit Path: g2news2.google.com!news3.google.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada Subject: Re: How do I write directly to a memory address? Date: Mon, 07 Feb 2011 07:38:47 +0100 Organization: Tidorum Ltd Message-ID: <8r9iboFkfvU1@mid.individual.net> 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> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net 1dDYn58zjPIfpzZUwshsOALSmNZTh6E8aBMq5iEfpQXw8P5+B9 Cancel-Lock: sha1:8MEhW+8EghQYiT2Cdxp/hoeQILg= User-Agent: Mozilla-Thunderbird 2.0.0.24 (X11/20100328) In-Reply-To: <883b7161-15ee-4874-95bb-2e0273dab51d@y36g2000pra.googlegroups.com> Xref: g2news2.google.com comp.lang.ada:17883 Date: 2011-02-07T07:38:47+01:00 List-Id: Shark8 wrote: > On Feb 6, 2:27 pm, Maciej Sobczak wrote: >> On Feb 6, 9:01 pm, "Dmitry A. Kazakov" >> wrote: >> >>> Immutable scalar arguments still ire mutable within C and C++ subprograms. >> Scalar arguments are passed by copy, so whether they are immutable or >> mutable within the function is independent on their origin (and the >> original is not affected by this in any way). >> >> Unless, of course, you have meant something else. > > The scalar-argument that is passed when dealing with strings/arrays > [in C & C++] is that of the address, IIRC. While that address is > itself an "immutable scalar" the data pointed to is not so constrained > and so may be 'mutated' thereby enabling a perceived-immutable to be > altered. {The newer standards may [or may not] have addressed this > issue: I seem to recall a "pointer to constant" idea which would > [I believe] behave in the expected manner if it was passed as the > parameter.} From the C99 standard, section 6.7.5.1, "Pointer declarators": EXAMPLE The following pair of declarations demonstrates the difference between a "variable pointer to a constant value" and a "constant pointer to a variable value". const int *ptr_to_constant; int *const constant_ptr; The contents of any object pointed to by ptr_to_constant shall not be modified through that pointer, but ptr_to_constant itself may be changed to point to another object. Similarly, the contents of the int pointed to by constant_ptr may be modified, but constant_ptr itself shall always point to the same location. In the first case, the protection is not removed by pointer arithmetic or array indexing, so ptr_to_constant+8 is also a pointer to a constant int. The constraints can be removed by "casting away" the "constant" quality. -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ .