• Re: Using gotos with local variables in "extra" blocks: Does it get dea

    From Tim Rentsch@3:633/10 to All on Sunday, May 31, 2026 16:24:17
    Subject: Re: Using gotos with local variables in "extra" blocks: Does it get deallocated?

    scott@slp53.sl.home (Scott Lurndal) writes:

    [asking about when the storage for local variables in
    nested blocks will be deallocated]

    Experimenting with gcc (4.8.3, 14.2.1) shows that the
    stack layout depends on -O.

    Sure. Isn't that what anyone would expect? (Not meant
    rhetorically.)

    int fff(int yyy, int xxx)
    {
    int ab = yyy + xxx;

    {
    int bb;
    printf("%p\n", &bb);
    }

    {
    int bc;
    printf("%p\n", &bc);
    }

    printf("%p\n", &ab);

    return 0;
    }

    This function has undefined behavior.

    --- PyGate Linux v1.5.15
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Keith Thompson@3:633/10 to All on Sunday, May 31, 2026 16:36:21
    Subject: Re: Using gotos with local variables in "extra" blocks: Does it get deallocated?

    Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
    scott@slp53.sl.home (Scott Lurndal) writes:
    [...]
    int fff(int yyy, int xxx)
    {
    int ab = yyy + xxx;

    {
    int bb;
    printf("%p\n", &bb);
    }

    {
    int bc;
    printf("%p\n", &bc);
    }

    printf("%p\n", &ab);

    return 0;
    }

    This function has undefined behavior.

    Yes, it has undefined behavior because "%p" requires an argument
    of type void*. The second argument in each printf call should be
    cast to void*.

    Is that what you're referring to? Do you see any other instance
    of undefined behavior (assuming xxx + yyy doesn't overflow)?

    --
    Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
    void Void(void) { Void(); } /* The recursive call of the void */

    --- PyGate Linux v1.5.15
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)