Path: csiph.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.lang.c Subject: Re: switch/extension for see below strongly needed Date: Sun, 31 May 2026 17:00:39 -0700 Organization: A noiseless patient Spider Lines: 33 Message-ID: <86cxybdt94.fsf@linuxsc.com> References: <10uapjs$19723$1@dont-email.me> <10ub0u0$1anme$1@dont-email.me> <10ub56e$1bupb$1@kst.eternal-september.org> <10uc81u$1kd2r$1@dont-email.me> <86tss6gnah.fsf@linuxsc.com> <10uck6g$1mspc$1@dont-email.me> <10ucq46$1q161$1@dont-email.me> <10ucrv1$1qefe$1@dont-email.me> <10ued7n$29vhi$1@dont-email.me> <10ueen5$jvhi$2@dont-email.me> <10uej0o$2besu$1@dont-email.me> <10ufik8$2kv1j$1@dont-email.me> <10ufp1j$2nsig$1@dont-email.me> <10uftvh$2p4eo$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Date: Mon, 01 Jun 2026 00:00:44 +0000 (UTC) Injection-Info: dont-email.me; logging-data="1992268"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+AJp6FO8HsTkFeJMHmqlTOJsshRcEpyGs="; posting-host="931249e2bc9d85e6e23258ad4c33c174" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:45pBumCD1vUG7OL3L6tlKj5E/Bg= sha1:p5XSp/M19+HjdBl2YA/Tlu/qC+0= sha256:xLI9OBNvPjSQIOsIRtj9ZgyCRQCJFFlWqlCWRogUm6c= sha1:n6Q27tID7mnRYVusEBUnxYML3tQ= Xref: csiph.com comp.lang.c:399574 Bart writes: > Every time I do a survey of C codebases, I tend to get about the > same set of results: > > * On average functions have only around three local variables > > * 80% of all functions have 4 locals or fewer Here are some statistics from a codebase for a C library: Average number of locals per function: just over 2 Fraction of functions with 4 locals or fewer: just over 85% What conclusions should we draw from these statistics? > I don't find such stats a compelling reason for block scopes, As most people know, a problem with averages is that they rarely tell the whole story. Despite the similarity of the statistics shown above with the ones you gave, code in the library codebase has locals declared in inner blocks, and locals declared in the outermost block but after some number of executable statements, and also locals declared in other nested scopes. In no case were any of these choices made from indifference: the code shows a clear preference for declaring locals in the outermost block, and at the top of that block before any executable code. In every instance that doesn't follow that rule there was a particular motivation for adopting the choice that was made. The idea that such averages make a good argument for never accepting locals other than at the top of the outermost block just doesn't hold water.