Обсуждение: persistent variables between cross-calls in C functions

Поиск
Список
Период
Сортировка

persistent variables between cross-calls in C functions

От
"ff"
Дата:
Dear all:

I could not find any way to store a value in a C function
between calls.

For example, the following function doesn't work as expected:
#include "postgres.h"#include "fmgr.h"

PG_FUNCTION_INFO_V1(next_value);
Datumnext_value(PG_FUNCTION_ARGS){    static int n;    PG_RETURN_INT32(n);    n++;}


select next_value();
will always return 0;

even if I declare n as a global variable outside the fucntion.


Thanks a lot.

Fabio Furia Silva



---
UOL, o melhor da Internet
http://www.uol.com.br/



Re: persistent variables between cross-calls in C functions

От
Tom Lane
Дата:
"ff" <ff-@uol.com.br> writes:
> I could not find any way to store a value in a C function
> between calls.

A static variable such as you illustrated should work fine --- at least
for successive calls within a single session.  It will not provide
communications across sessions.  For that you'd need to use a file or
grab some shared memory (this is doable but bear in mind that it's a
very finite resource).
        regards, tom lane



Re: persistent variables between cross-calls in C functions

От
"ff"
Дата:
> "ff" <ff-@uol.com.br> writes:
> > I could not find any way to store a value in a C function
> > between calls.
>
> A static variable such as you illustrated should work fine -
-- at least
> for successive calls within a single session.  It will not p
rovide
> communications across sessions.  For that you'd need to use
a file or
> grab some shared memory (this is doable but bear in mind tha
t it's a
> very finite resource).
>
>             regards, tom lane
>
>

Thanks, Tom!
But it isn't working.
Even inside the same session (I do not want to provide
communications across sessions).

Is there any macro provided in any c header file that I
should use?

I am using postgresql version 7.3.2, on AIX 4.3 (and all
patches).

Thanks again.


---
UOL, o melhor da Internet
http://www.uol.com.br/