From owner-freebsd-hackers Wed Oct 24 5:58:57 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from straylight.ringlet.net (sentinel.office1.bg [217.75.129.210]) by hub.freebsd.org (Postfix) with SMTP id CDEAB37B403 for ; Wed, 24 Oct 2001 05:58:48 -0700 (PDT) Received: (qmail 1489 invoked by uid 1000); 24 Oct 2001 12:58:41 -0000 Date: Wed, 24 Oct 2001 15:58:41 +0300 From: Peter Pentchev To: "Alexey V . Neyman" Cc: freebsd-hackers@freebsd.org Subject: Re: strange code? Message-ID: <20011024155841.B975@straylight.oblivion.bg> Mail-Followup-To: "Alexey V . Neyman" , freebsd-hackers@freebsd.org References: <0110241653120B.01031@vagabond.auriga.ru> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <0110241653120B.01031@vagabond.auriga.ru>; from alex.neyman@auriga.ru on Wed, Oct 24, 2001 at 04:53:12PM +0400 Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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