Re: [HACKERS] Does this make sense:

From: geek+(at)cmu(dot)edu
To: pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: [HACKERS] Does this make sense:
Date: 1998-12-14 15:21:12
Message-ID: emacs-smtp-743-13941-11496-797451@export.andrew.cmu.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Then <scrappy(at)hub(dot)org> spoke up and said:
>
> char *
> crypt_getpwdfilename()
> {
>
> static char *pfnam = NULL;
>
> if (!pfnam)
> {
> int bufsize;
> bufsize = strlen(DataDir) + strlen(CRYPT_PWD_FILE) + 2;
> pfnam = (char *) palloc(bufsize);
> spprintf(pfnam, bufsize, "%s/%s", DataDir, CRYPT_PWD_FILE);
> }
>
> return pfnam;
> }
>
> Why the check for '!ipfnam'? Seems useless since we are setting it to
> NULL the line before...no?

static variables should be thought of as globals with only local
scope. This variable is allocated in the BSS area rather than on the
stack at runtime. The initialization is performed only once (usually
at compile time), and the value is retained from execution to
execution. Basically, it always returns the previously computed
filename except for the very first call.

--
=====================================================================
| JAVA must have been developed in the wilds of West Virginia. |
| After all, why else would it support only single inheritance?? |
=====================================================================
| Finger geek(at)andrew(dot)cmu(dot)edu for my public key. |
=====================================================================

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 1998-12-14 16:00:33 Re: [HACKERS] palloc() vs static define?
Previous Message Bruce Momjian 1998-12-14 15:09:40 Re: Re[2]: [HACKERS] BUG ON HAVING CLAUSE