[OCLUG-devel] strcpy segmentation faults

Doug Jolley ddjolley at gmail.com
Thu Jun 23 23:01:12 PDT 2005


> 5) Because it's declared "char*" (as opposed to const char*),
> REALLY_CONSTANT itself is not constant, nor is it necessarily pointing
> to a constant. It's just the stuff it's pointing to initially is
> (because it's a literal string). 

Well, if you would have left out the phrase beginning with 'nor', I
would have said that I get it.  The difference between 'char*' and
'const char*'  is that 'char*' is a pointer variable (that may be
changed) and is pointing to a literal/constant string while 'const
char*' is a pointer constant pointing to the same thing.  So, in the
first case we have a pointer variable that can be changed pointing to
a literal/constant string and in the second case we have a constant
pointer pointing to the same thing.  That's what I would have said if
you had omitted the phrase beginning with 'nor'.  With that phrase I'm
not sure what to think.  It sounds like you see a distinction between
a string constant and a string literal.  I'm not sure I understand
that distinction.

In order to avoid obscuring the issue, let's take the pointers out of
it for a minute.  Do you see a difference between:

       char myVar[] = "My dog has fleas.";

and

       const myVar char[] = "My dog has fleas.";

Before we began this discussion I would have said that the difference
is that the first is a variable that can be changed and the second is
a constant that can't be changed.  I thought what you were telling me
is that there is now no difference.  Have I missed the point here?  It
doesn't seem like loosing the flexibility to go either way would be an
advantage.  Am I confused?

Thanks.

     ... doug (Not digitally signed.)


More information about the OCLUG-devel mailing list