🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #27163

Re: innd - source q1

#27163
From: Forrest J. Cavalier III
Date: Wed, 25 Mar 1998 00:00
55 lines
2291 bytes
In article <6fangr$o2g$1@flis.man.torun.pl>, makler@man.torun.pl wrote...
>
>INND source question  no. 1
>
>I see in the library libinn.a, there is a source file called
>getmodaddr.c, that has a function GetModeratorAddress:
><snip>
>/*
>**  Read the moderators file, looking for a moderator.
>*/
>char *
>GetModeratorAddress(FromServer, ToServer, group)
>    FILE                *FromServer;
>    FILE                *ToServer;
>    char                *group;
>{
>    static char         address[SMBUF];
>    register char       *p;
>    char                *save;
>    char                buff[BUFSIZ];
>    char                name[SMBUF];
>
>    (void)strcpy(name, group);
>    address[0] = '\0';
>    ...
></snip>
>
>Why address[SMBUF] is declared as static, if this is cut
>to null string in the line address[0] = '\0'.
>

The assignment to null string is not relevant.  That is
to initialize a default value if the subsequent loop fails
to assign a value.

There are three reasons that I can think of (off the top of
my head) to declare a variable static within a function body:
   1. To save "state" in between function activations.

   2. To place large arrays outside the stack.

   3. To provide a return value that doesn't get destroyed
      when the stack frame is cleared when the function returns.

It is for reason #3 that GetModeratorAddress() declares
address[] static.

Forrest J. Cavalier III, Mib Software, INN customization and consulting 
'Pay-as-you-go' commercial support for INN: Only $64/hour! 
Searchable hypertext INN docs, FAQ, RFCs, etc: 650+ pages: Free access! 
   http://www.mibsoftware.com/innsup.htm 


Technical Details
Message-ID: <6fb2cf$b1c$1@nntp.epix.net>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!not-for-mail
References: <6fangr$o2g$1@flis.man.torun.pl>

Show Full Headers
Complete Article Headers
Message-ID: <6fb2cf$b1c$1@nntp.epix.net>
Subject: Re: innd - source q1
Date: Wed, 25 Mar 1998 00:00:00 +0000
From: mibsoft@mibsoftware.com (Forrest J. Cavalier III)
References: <6fangr$o2g$1@flis.man.torun.pl>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!not-for-mail
X-Deja-AN: 337521367
Mime-Version: 1.0
Content-Type: Text/Plain; charset=US-ASCII
Organization: Mib Software
Newsgroups: news.software.nntp