Re: [HACKERS] Does this make sense: - Mailing list pgsql-hackers

From geek+@cmu.edu
Subject Re: [HACKERS] Does this make sense:
Date
Msg-id emacs-smtp-743-13941-11496-797451@export.andrew.cmu.edu
Whole thread Raw
In response to Does this make sense:  (The Hermit Hacker <scrappy@hub.org>)
List pgsql-hackers
Then <scrappy@hub.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@andrew.cmu.edu for my public key.                     |
=====================================================================

pgsql-hackers by date:

Previous
From: jwieck@debis.com (Jan Wieck)
Date:
Subject: Re: [HACKERS] Does this make sense:
Next
From: Hannu Krosing
Date:
Subject: Re: [HACKERS] JOIN syntax. Examples?