Thread View: news.software.nntp
3 messages
3 total messages
Started by makler
Wed, 25 Mar 1998 00:00
innd - source q1
Author: makler
Date: Wed, 25 Mar 1998 00:00
Date: Wed, 25 Mar 1998 00:00
38 lines
1365 bytes
1365 bytes
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'.
P.K.
--
makler@man.torun.pl
--
Piotr Klaban
--
makler@man.torun.pl
Re: innd - source q1
Author: Forrest J. Cavalier III
Date: Wed, 25 Mar 1998 00:00
Date: Wed, 25 Mar 1998 00:00
55 lines
2291 bytes
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
Re: innd - source q1
Author: Sven Paulus
Date: Wed, 25 Mar 1998 00:00
Date: Wed, 25 Mar 1998 00:00
24 lines
1284 bytes
1284 bytes
makler@man.torun.pl wrote: mmtp> address[0] = '\0'; mmtp> Why address[SMBUF] is declared as static, if this is cut mmtp> to null string in the line address[0] = '\0'. Continue reading the source file a few lines, you'll find: if (*p == '.') *p = '-'; >>>> (void)sprintf(address, save, name); break; This is the main reason for address[] being static. What you saw was only the initialzation of the variable. Sven -- --Sven-Paulus----------28-48-32--3-----ub6v@rz.uni-karlsruhe.de------ --Karlstr.-55----------30--2-50-29-----sven@oops.sub.de-------------- --D-76133-Karlsruhe----44-49-10--8-----T#-49-721-9375094---------irc- --PGP-ID-3C9A6091-------9-12-19-71-----F#-49-721-9375095-----svennie-
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads