Re: [GENERAL] Persistent variables between cross-calls in C functions

Поиск
Список
Период
Сортировка
От Stephan Szabo
Тема Re: [GENERAL] Persistent variables between cross-calls in C functions
Дата
Msg-id 20030325094939.W41500-100000@megazone23.bigpanda.com
обсуждение исходный текст
Ответ на Persistent variables between cross-calls in C functions  ("Fabio Furia Silva" <ff-@uol.com.br>)
Список pgsql-hackers
On Tue, 25 Mar 2003, Fabio Furia Silva wrote:

> For example, the following function doesn't work as expected:
>
> /********************************/
>     #include "postgres.h"
>     #include "fmgr.h"
>
>     PG_FUNCTION_INFO_V1(next_value);
>
>     Datum next_value(PG_FUNCTION_ARGS)
>     {
>     static int n;
>     PG_RETURN_INT32(n);
>     n++;
>     }
>
> /********************************/
>     create function next_value()
>     returns integer as
>     'next.so' language C;
>
> /********************************/
> Calling
>
>     select next_value();
>
> will always return 0,
> even if I declare 'n' as a global variable outside the C function.

Which seems right since the n++ is never executed (being after the return
statement).  Does it do what you want if you increment first?


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

Предыдущее
От: "Fabio Furia Silva"
Дата:
Сообщение: Persistent variables between cross-calls in C functions
Следующее
От: Oleg Bartunov
Дата:
Сообщение: Re: New structers for optimazing R-tree