D
DSF
Hello.
I have written several functions that take a char ** pointer. Since
these functions do not alter the pointer array or the character
arrays, I feel it's good to label the pointer as const.
I have two concerns:
1. I'm a little rusty on the meaning of const in this case. Does it
indicate that the pointer array will not be altered, the character
arrays will not be altered, or both? What are the usable
permutations?
2. Any call to say,
int foo(const char **ca);
....
int r;
char *c;
char **c_array;
....
r = foo(c_array);
requires a cast
r = foo((const **)c_array);
or I receive a "suspicious pointer conversion" warning.
Is it better to use const and cast each call to foo, or omit the
const? On one hand, identifying ca as const seems the right thing to
do, but on the other hand, requiring the cast allows for bugs.
r = foo((const **)c);
Will compile without a peep from the compiler that something nasty
has just occurred.
What is the proper way to handle this?
DSF
I have written several functions that take a char ** pointer. Since
these functions do not alter the pointer array or the character
arrays, I feel it's good to label the pointer as const.
I have two concerns:
1. I'm a little rusty on the meaning of const in this case. Does it
indicate that the pointer array will not be altered, the character
arrays will not be altered, or both? What are the usable
permutations?
2. Any call to say,
int foo(const char **ca);
....
int r;
char *c;
char **c_array;
....
r = foo(c_array);
requires a cast
r = foo((const **)c_array);
or I receive a "suspicious pointer conversion" warning.
Is it better to use const and cast each call to foo, or omit the
const? On one hand, identifying ca as const seems the right thing to
do, but on the other hand, requiring the cast allows for bugs.
r = foo((const **)c);
Will compile without a peep from the compiler that something nasty
has just occurred.
What is the proper way to handle this?
DSF