Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #399437

Variables in inner blocks (was: Using gotos with local variables in "extra" blocks: Does it get deallocated?)

From pa@see.signature.invalid (Pierre Asselin)
Newsgroups comp.lang.c
Subject Variables in inner blocks (was: Using gotos with local variables in "extra" blocks: Does it get deallocated?)
Date 2026-05-25 19:52 +0000
Organization PANIX Public Access Internet and UNIX, NYC
Message-ID <10v2993$699$1@reader1.panix.com> (permalink)
References <10v1jrr$35gqh$2@news.xmission.com> <10v1toh$qrb$1@reader1.panix.com> <DY%QR.370372$gO1.309583@fx14.iad>

Show all headers | View raw


Scott Lurndal <scott@slp53.sl.home> wrote:

> In believe in most cases, the compiler simply adds the required
> storage space for all variables defined in inner-blocks to the
> initial stack allocation on function entry. Which is all "deallocated"
> when the function returns.

Yeah, I believe so. But in some code I was working on back in 2009,
I had the following pattern in a function that called itself
recursively:

    static void fou(struct something *x)
    {
	struct something *y[3];
	{
	    /* declare many more variables */
	    /* do things that fill the y[] array of pointers */
	}
	if(y[0]) fou(y[0]);
	if(y[1]) fou(y[1]);
	if(y[2]) fou(y[2]);
    }

I put most of the function body in an inner block, hoping that the
inner variables would be deallocated before the recursive phase
and that stack usage would be reduced.

I don't think my micro-optimization worked. It didn't matter,
even with the larger stack frame the function never came close
to blowing up.

(It was a part of a 3D tetrahedral mesher. I'll have to try
with a small self-contained example and look at the assembler.)

-- 
pa at panix dot com

Back to comp.lang.c | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Using gotos with local variables in "extra" blocks: Does it get deallocated? gazelle@shell.xmission.com (Kenny McCormack) - 2026-05-25 13:46 +0000
  Re: Using gotos with local variables in "extra" blocks: Does it get deallocated? Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-05-25 16:19 +0200
  Re: Using gotos with local variables in "extra" blocks: Does it get deallocated? Bart <bc@freeuk.com> - 2026-05-25 15:21 +0100
    The C23 thing (Was: Using gotos with local variables in "extra" blocks: Does it get) deallocated? gazelle@shell.xmission.com (Kenny McCormack) - 2026-05-25 14:32 +0000
    Re: Using gotos with local variables in "extra" blocks: Does it get deallocated? Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-05-25 16:34 +0200
  Re: Using gotos with local variables in "extra" blocks: Does it get deallocated? Andrew Smallshaw <andrews@sdf.org> - 2026-05-25 16:09 +0000
    The whole point of this NG is worrying about "UB" (Was: Using gotos with local variables in "extra" blocks: Does it get) deallocated? gazelle@shell.xmission.com (Kenny McCormack) - 2026-05-25 16:54 +0000
      Re: The whole point of this NG is worrying about "UB" (Was: Using gotos with local variables in "extra" blocks: Does it get) deallocated? Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-05-25 19:08 +0200
        Re: The whole point of this NG is worrying about "UB" (Was: Using gotos with local variables in "extra" blocks: Does it get) deallocated? gazelle@shell.xmission.com (Kenny McCormack) - 2026-05-25 17:23 +0000
          Re: The whole point of this NG is worrying about "UB" (Was: Using gotos with local variables in "extra" blocks: Does it get) deallocated? Bart <bc@freeuk.com> - 2026-05-25 18:48 +0100
  Re: Using gotos with local variables in "extra" blocks: Does it get deallocated? cross@spitfire.i.gajendra.net (Dan Cross) - 2026-05-25 16:35 +0000
    Re: Using gotos with local variables in "extra" blocks: Does it get deallocated? scott@slp53.sl.home (Scott Lurndal) - 2026-05-25 17:49 +0000
      Variables in inner blocks (was: Using gotos with local variables in "extra" blocks: Does it get deallocated?) pa@see.signature.invalid (Pierre Asselin) - 2026-05-25 19:52 +0000
      Re: Using gotos with local variables in "extra" blocks: Does it get deallocated? cross@spitfire.i.gajendra.net (Dan Cross) - 2026-05-26 14:13 +0000
        Re: Using gotos with local variables in "extra" blocks: Does it get deallocated? scott@slp53.sl.home (Scott Lurndal) - 2026-05-26 17:10 +0000
          Re: Using gotos with local variables in "extra" blocks: Does it get deallocated? David Brown <david.brown@hesbynett.no> - 2026-05-26 20:31 +0200
          Re: Using gotos with local variables in "extra" blocks: Does it get deallocated? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-05-31 16:24 -0700
            Re: Using gotos with local variables in "extra" blocks: Does it get deallocated? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-05-31 16:36 -0700
  Re: Using gotos with local variables in "extra" blocks: Does it get deallocated? David Brown <david.brown@hesbynett.no> - 2026-05-25 18:40 +0200
  Re: Using gotos with local variables in "extra" blocks: Does it get deallocated? Lynn McGuire <lynnmcguire5@gmail.com> - 2026-05-26 17:14 -0500
    Re: Using gotos with local variables in "extra" blocks: Does it get deallocated? cross@spitfire.i.gajendra.net (Dan Cross) - 2026-05-27 00:23 +0000
      Re: Using gotos with local variables in "extra" blocks: Does it get deallocated? gazelle@shell.xmission.com (Kenny McCormack) - 2026-05-27 02:09 +0000
      Re: Using gotos with local variables in "extra" blocks: Does it get deallocated? Lynn McGuire <lynnmcguire5@gmail.com> - 2026-05-26 22:51 -0500
        Re: Using gotos with local variables in "extra" blocks: Does it get deallocated? Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-05-27 04:46 +0000
          Re: Using gotos with local variables in "extra" blocks: Does it get deallocated? David Brown <david.brown@hesbynett.no> - 2026-05-27 09:21 +0200
        Re: Using gotos with local variables in "extra" blocks: Does it get deallocated? cross@spitfire.i.gajendra.net (Dan Cross) - 2026-05-27 12:40 +0000
          Re: Using gotos with local variables in "extra" blocks: Does it get deallocated? scott@slp53.sl.home (Scott Lurndal) - 2026-05-27 14:48 +0000
          Re: Using gotos with local variables in "extra" blocks: Does it get deallocated? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-05-27 13:39 -0700
            Re: Using gotos with local variables in "extra" blocks: Does it get deallocated? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-05-27 17:04 -0700
              Re: Using gotos with local variables in "extra" blocks: Does it get deallocated? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-05-27 18:16 -0700
          Re: Using gotos with local variables in "extra" blocks: Does it get deallocated? antispam@fricas.org (Waldek Hebisch) - 2026-05-28 00:35 +0000
            Re: Using gotos with local variables in "extra" blocks: Does it get deallocated? Mike Terry <news.dead.person.stones@darjeeling.plus.com> - 2026-05-29 04:01 +0100
        Re: Using gotos with local variables in "extra" blocks: Does it get deallocated? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-05-27 13:32 -0700
  Re: Using gotos with local variables in "extra" blocks: Does it get deallocated? fir <profesor.fir@gmail.com> - 2026-05-27 15:33 +0200
    Re: Using gotos with local variables in "extra" blocks: Does it get deallocated? Bart <bc@freeuk.com> - 2026-05-27 17:18 +0100
      Re: Using gotos with local variables in "extra" blocks: Does it get deallocated? fir <profesor.fir@gmail.com> - 2026-05-27 18:51 +0200
        Re: Using gotos with local variables in "extra" blocks: Does it get deallocated? fir <profesor.fir@gmail.com> - 2026-05-27 18:56 +0200
    Re: Using gotos with local variables in "extra" blocks: Does it get deallocated? Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-05-27 22:42 +0000
      Re: Using gotos with local variables in "extra" blocks: Does it get deallocated? fir <profesor.fir@gmail.com> - 2026-05-28 07:33 +0200
        Re: Using gotos with local variables in "extra" blocks: Does it get deallocated? Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-05-28 05:37 +0000
          Re: Using gotos with local variables in "extra" blocks: Does it get deallocated? fir <profesor.fir@gmail.com> - 2026-05-28 17:35 +0200
            Re: Using gotos with local variables in "extra" blocks: Does it get deallocated? Bart <bc@freeuk.com> - 2026-05-28 16:49 +0100
              Re: Using gotos with local variables in "extra" blocks: Does it get deallocated? fir <profesor.fir@gmail.com> - 2026-05-28 18:04 +0200

csiph-web