Re: A couple more PostgreSQL C questions

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: A couple more PostgreSQL C questions
Дата
Msg-id 16156.1162959480@sss.pgh.pa.us
обсуждение исходный текст
Ответ на A couple more PostgreSQL C questions  (Ron Peterson <ron.peterson@yellowbank.com>)
Список pgsql-general
Ron Peterson <ron.peterson@yellowbank.com> writes:
> Datum
> y_somefunc ( PG_FUNCTION_ARGS )
> {
>    if( PG_ARGISNULL(0) ||
>        PG_ARGISNULL(1) ||
>        PG_ARGISNULL(2) )
>    {
>       PG_RETURN_NULL();
>    }
>    text* rand_dev = PG_GETARG_TEXT_P(0);
>    ...

> Should I be concerned by this?  What's the proper way to code this?

The proper way to code that is either

{
   text* rand_dev;

   if( PG_ARGISNULL(0) ||
       PG_ARGISNULL(1) ||
       PG_ARGISNULL(2) )
   {
      PG_RETURN_NULL();
   }
   rand_dev = PG_GETARG_TEXT_P(0);
   ...

or probably better, declare the function STRICT and drop the runtime
ARGISNULL tests entirely.

> I'm thinking the correct answer is "just live with
> it until your version of gcc uses c99 as the default standard".

Declarations in the middle of a code block are C++, not C; if you
try to hold your breath until your C compiler accepts it, you will die.

            regards, tom lane

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

Предыдущее
От: Ron Peterson
Дата:
Сообщение: Re: A couple more PostgreSQL C questions
Следующее
От: "Gurjeet Singh"
Дата:
Сообщение: Re: Per-row security