Re: Problem with PQexecPrepared

Поиск
Список
Период
Сортировка
От Jeroen T. Vermeulen
Тема Re: Problem with PQexecPrepared
Дата
Msg-id 20040609222114.GI91662@xs4all.nl
обсуждение исходный текст
Ответ на Problem with PQexecPrepared  (David Stanaway <david@stanaway.net>)
Ответы Re: Problem with PQexecPrepared  (David Stanaway <david@stanaway.net>)
Список pgsql-interfaces
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!


Jeroen



В списке pgsql-interfaces по дате отправления:

Предыдущее
От: David Stanaway
Дата:
Сообщение: Problem with PQexecPrepared
Следующее
От: Brett Schwarz
Дата:
Сообщение: Re: A doubt in pgtcl