On 2008-08-14 09:58-0500 Maurice LeBrun wrote:

> For C & C++, a const pointer means the memory it points to cannot be altered.
> The pointer can.  So for example
>
>    const char *foo = "bar";
>
> (or later reassignment) is perfectly legit.

After years of dabbling at C, this pointer stuff still makes my head spin so
could you expand a bit more, Maurice?  What actually happens with the above
statement?  After the declaration of foo as a pointer to a const char is foo
initialized as a pointer to the first character in the const "bar" string?
Or would a better way to look at it be that all character strings like "bar"
can be interpreted as pointers so the above is simply a pointer assignment?

Is this a good example of the later reassignment you referred to?

*foo = "whatever";

or would it be

foo = "whatever";
?

The first seems consistent with the mnemonic for the declaration, but I am
virtually positive the latter is correct instead since *foo would refer to
the first read-only character in "bar" which would make no sense for an
assignment.

Thanks in advance for trying to deal with my confusion on these issues.  I
guess the start of my confusion all these years has been what I consider to
be a rather illogical mnemonic for pointer declarations using the
dereferencing operator.  I guess I just got off on the wrong foot with C
pointers and have never recovered.  :-)

Alan
__________________________
Alan W. Irwin

Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).

Programming affiliations with the FreeEOS equation-of-state implementation
for stellar interiors (freeeos.sf.net); PLplot scientific plotting software
package (plplot.org); the libLASi project (unifont.org/lasi); the Loads of
Linux Links project (loll.sf.net); and the Linux Brochure Project
(lbproject.sf.net).
__________________________

Linux-powered Science
__________________________

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Plplot-devel mailing list
Plplot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/plplot-devel

Reply via email to