Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 24 Oct 2001 15:58:41 +0300
From:      Peter Pentchev <roam@ringlet.net>
To:        "Alexey V . Neyman" <alex.neyman@auriga.ru>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: strange code?
Message-ID:  <20011024155841.B975@straylight.oblivion.bg>
In-Reply-To: <0110241653120B.01031@vagabond.auriga.ru>; from alex.neyman@auriga.ru on Wed, Oct 24, 2001 at 04:53:12PM %2B0400
References:  <0110241653120B.01031@vagabond.auriga.ru>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, Oct 24, 2001 at 04:53:12PM +0400, Alexey V . Neyman wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Hello there!
> 
> I've stumbled accross the following in sys/netinet/ip_input.c (v.1.173)
> 
> - --- lines 470-477 ---
>         if (m == NULL) {    /* Packet discarded by firewall */
>             static int __debug=10;
>             if (__debug >0) {
>             printf("firewall returns NULL, please update!\n");
>             __debug-- ;
>             }
>             return;
>         }
> 
> What is the meaning of this construct? Isn't it functionally equivalent to
> 
>         if (m == NULL) {     /* Packet discarded by firewall */
> 	    printf("firewall returns NULL, please update!\n");
> 	    return;
> 	}

No.  This is a C syntax issue: if a variable local to a function is
declared as static, this means that it is initialized to the specified
value once at program start, and then its value is preserved across
function calls.  That is, the variable does not start over from 10
each time; it starts at 10 at boot time, then with each pass through
this piece of code its value is decremented.  At the tenth pass since
boottime, its value reaches 0 and no more warnings are printed out.

G'luck,
Peter

-- 
This sentence would be seven words long if it were six words shorter.

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20011024155841.B975>