|
|
nembo kid <user@xxxxxxxxxxxxx> writes:
> Richard Heathfield ha scritto:
>> Why not? It's only a copy, after all. It doesn't affect the original
>> array address in any way whatsoever.
>
> Ok my doubts cleared all.
>
> But anyway I dont'understand because someone add the qualificator
> "const" to string array passed to the function (so to avoid any change
> of this pointer).
> /* Code */
> void chartobyte (const char *s)
> /* Code */
``const char *s'' declares s as a pointer to const char, not as a
const pointer to char. In other words, you're permitted to modify the
pointer (since it's just a local copy), but you're not permitted to
modify what it points to.
If you wanted to declare a const pointer to char (so the pointer
itself is read-only), you could write:
char *const s;
But function parameters, since they're purely local to the function,
are not typically declared as "const", since any modification won't
affect the caller anyway. You could declare a parameter as "const" if
you don't intend to modify it within the function.
--
Keith Thompson (The_Other_Keith) <kst-u@xxxxxxx>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
|
|