Skip site navigation (1) Skip section navigation (2)

Re: Persistent variables between cross-calls in C functions

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Fabio Furia Silva <ff-(at)uol(dot)com(dot)br>
Cc: <pgsql-hackers(at)postgresql(dot)org>, <pgsql-general(at)postgresql(dot)org>,<pgsql-interfaces(at)postgresql(dot)org>
Subject: Re: Persistent variables between cross-calls in C functions
Date: 2003-03-25 17:51:54
Message-ID: 20030325094939.W41500-100000@megazone23.bigpanda.com (view raw or flat)
Thread:
Lists: pgsql-generalpgsql-hackerspgsql-interfaces
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?


In response to

pgsql-hackers by date

Next:From: Oleg BartunovDate: 2003-03-25 17:55:35
Subject: Re: New structers for optimazing R-tree
Previous:From: Josh BerkusDate: 2003-03-25 17:28:09
Subject: Re: to_char(interval) --- done?

pgsql-interfaces by date

Next:From: Rudy LippanDate: 2003-03-26 04:29:07
Subject: Re: Prepare and prepare ?
Previous:From: Fabio Furia SilvaDate: 2003-03-25 16:12:00
Subject: Persistent variables between cross-calls in C functions

pgsql-general by date

Next:From: scott.marloweDate: 2003-03-25 17:52:17
Subject: Re: '' <> NULL
Previous:From: Bodanapu, SravanDate: 2003-03-25 17:11:41
Subject: Issue with Rowid's during Oracle to Postgres convertion:

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group