On Wed, Jun 09, 2004 at 04:44:12PM -0500, David Stanaway wrote:
> The type I am passing is a char** and it is expecting const char* const*
I'm not sure I understand your question entirely, so forgive me if I'm
telling you things you already know...
The C type system needs to be strict here to guard against the case where
people try pass a "char **" argument to a "const char **" parameter.
Why is that a problem?
Because the function might try to insert a "const char *" into the array,
thinking it got passed an array of "const char *"s. But after the function
returned, the caller might overwrite the actual string this pointer pointed
to because it never told the function that the chars were to be kept const.
This is a case where "adding a const" is not type-safe.
Not that it would be a problem here, because the array itself is const
and so the function could never write its own pointer into it. I think
it's one of those rare situations where a cast is justified.
> The parameters I am passing in a generated at runtime so I can supply a
> const pointer.
Generating something at runtime doesn't mean you can't have a const pointer
to it. Declaring the thing a pointer points to "const" is a promise that
you won't use the pointer to modify that thing. Which doesn't mean that
it can't be modified through another pointer!
In response to
pgsql-interfaces by date
|Next:||From: Brett Schwarz||Date: 2004-06-09 22:35:30|
|Subject: Re: A doubt in pgtcl|
|Previous:||From: David Stanaway||Date: 2004-06-09 21:44:12|
|Subject: Problem with PQexecPrepared|