• =?UTF-8?Q?Re=3A_=E2=80=9CThe_end_of_software_secrecy_is_almost_upon?=

    From Johann 'Myrkraverk' Oskarsson@johann@myrkraverk.invalid to comp.lang.fortran,comp.lang.c++,alt.comp.lang.rust,alt.folklore.computers,comp.lang.misc on Wed Oct 21 20:09:42 2026
    From Newsgroup: comp.lang.misc

    On 10/21/2026 7:18 AM, Charlie Gibbs wrote:
    On 2026-10-20, Lawrence DrCOOliveiro <ldo@nz.invalid> wrote:

    On Tue, 20 Oct 2026 19:04:55 GMT, Charlie Gibbs wrote:

    The undisciplined use of GOTOs is bad, agreed.

    Is there such a thing as a *disciplined* use of gotos?

    Yes, especially in COBOL or assembly language. For instance,
    a GOTO to the end of a function ensures any of its cleanup code
    gets executed, and fulfils a goal of structured proramming:
    each function has one exit point.

    I find the C code I write tends to do a lot of dynamic resource
    allocations. These can sometimes fail with errors. So error recovery
    will invariably involve cleaning up those parts of the allocations
    which already succeeded. Gotos are no good for this; you need to exit
    levels of structure nesting one by one, disposing of allocations as
    you go.

    I know that a lot of CS types are going to stick pins into little
    dolls that look like me for saying this, but IMHO resource pointers,
    handles, etc. should be global. Possible exceptions are resources
    that are going to be used solely by the current function - but even
    then, if that function calls another function that fails horribly,
    there's stuff that might not get cleaned up. That's why all my
    C programs contain a function quit_cleanup(char *errmsg), which
    de-allocates all resources and then exits (displaying "errmsg"
    if it isn't NULL). I can call that function anywhere, safe in
    the knowledge that by the time it finishes (it never returns),
    everything will have be freed.


    Side note: I chose not to comment on any of the other followups by the
    less experienced coders. I personally have no problem with your app-
    roach.

    That works for a single process, but once you start making libraries
    like Lua that can be loaded and then unloaded the rules change somewhat.

    SQLite3 can be used similarly.

    Though I doubt many people load either library dynamically, and then un-
    load; yet as far as I'm aware, both libraries support such usage.

    I added comp.lang.misc because I'm not aware of a Lua discussion group.

    Best wishes, and happy resource cleanup!
    --
    Johann | email: invalid -> com | http://www.myrkraverk.com/blog/
    I'm not from the Internet, I just work there. | via Easynews.com https://bsky.app/profile/myrkraverk.bsky.social | for ( ;; ) _:;
    Federated at https://fed.brid.gy/bsky/myrkraverk.bsky.social
    --- Synchronet 3.22a-Linux NewsLink 1.2