• pasing variadic arguments down

    From fir@3:633/10 to All on Fri Sep 11 13:25:03 2026
    ok if someone want regular c stuff
    (there still are some parts of c i dont learned (i got no tiem as they
    vere rarely used)it is this variadic stuff

    i once seen it like maybe outdated/obsolete/archaic stuff but in fact
    i had probably normie mind in this point - becouse later i discovered
    that this printf is not such bad in practice (im not sure if i would
    name it very good but if back then i got a view that my apps shouldnt
    use it and maybe i should use my own separate routines for printing text
    and numbers it showed to be more annoying (those print("ss");
    printN(23); print("aassaaas"); ) than printf

    but im not fully comprehending this varargs stuff and i think i should
    learn it (though its panful for old 50 year old man)

    so the question is the passing down the variadic arguments costly?

    how it work?

    i mean when you got function that takes varargs like

    void slog_yellow(char *format, ...)
    {
    SlogColor(0xffff00); va_list args; va_start(args, format); slog(format, args); va_end(args);

    }

    and you pass it down to oryginal slog() which also takes varargs

    void slog_(char *format, ...)
    {
    va_list args;
    va_start(args, format);
    int n = vsnprintf(&slog_[slog_top][0], slog_line_max, format, args);
    va_end(args);


    slog_top++;
    }

    which in turn as uit shows passes it down to vsnprintf

    does this passing is costly?


    as i dont understand this well in fact i may make some errors codng it
    (but as i said up the point i was not much fiery reasons to learn this)


    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From fir@3:633/10 to All on Fri Sep 11 14:04:03 2026
    fir pisze:
    ok if someone want regular c stuff
    (there still are some parts of c i dont learned (i got no tiem as they
    vere rarely used)it is this variadic stuff

    i once seen it like maybe outdated/obsolete/archaic stuff but in fact
    i had probably normie mind in this point - becouse later i discovered
    that this printf is not such bad in practice (im not sure if i would
    name it very good but if back then i got a view that my apps shouldnt
    use it and maybe i should use my own separate routines for printing text
    and numbers it showed to be more annoying (those print("ss");
    printN(23);ÿ print("aassaaas"); ) than printf

    but im not fully comprehending this varargs stuff and i think i should
    learn it (though its panful for old 50 year old man)

    so the question is the passing down the variadic arguments costly?

    how it work?

    i mean whenÿ you got function that takes varargs like

    ÿvoid slog_yellow(char *format, ...)
    ÿ{
    ÿÿÿ SlogColor(0xffff00);ÿÿÿ va_list args; va_start(args, format); slog(format, args);ÿÿÿ va_end(args);

    ÿ}

    and you pass it down to oryginal slog() which also takes varargs

    void slog_(char *format, ...)
    ÿ{
    ÿÿÿÿÿ va_list args;
    ÿÿÿÿÿ va_start(args, format);
    ÿÿÿÿ int n =ÿ vsnprintf(&slog_[slog_top][0], slog_line_max, format, args);
    ÿÿÿÿÿ va_end(args);


    ÿÿÿÿslog_top++;
    }

    which in turn as uit shows passes it down to vsnprintf

    does this passing is costly?


    as i dont understand this well in fact i may make some errors codng it
    (but as i said up the point i was not much fiery reasons to learn this)

    (the example here may be seen nonsense as i pass a color value than not
    use it but i jost got the slog updated to store colors alos in its ram
    to be ablo to write color mesages but skipped it for clarity of
    question, maybe i should put //.. there)

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From bart@3:633/10 to All on Fri Sep 11 13:05:13 2026
    On 11/09/2026 12:25, fir wrote:
    ok if someone want regular c stuff
    (there still are some parts of c i dont learned (i got no tiem as they
    vere rarely used)it is this variadic stuff

    i once seen it like maybe outdated/obsolete/archaic stuff but in fact
    i had probably normie mind in this point - becouse later i discovered
    that this printf is not such bad in practice (im not sure if i would
    name it very good but if back then i got a view that my apps shouldnt
    use it and maybe i should use my own separate routines for printing text
    and numbers it showed to be more annoying (those print("ss");
    printN(23);ÿ print("aassaaas"); ) than printf

    but im not fully comprehending this varargs stuff and i think i should
    learn it (though its panful for old 50 year old man)

    so the question is the passing down the variadic arguments costly?

    how it work?

    i mean whenÿ you got function that takes varargs like

    ÿvoid slog_yellow(char *format, ...)
    ÿ{
    ÿÿÿ SlogColor(0xffff00);ÿÿÿ va_list args; va_start(args, format); slog(format, args);ÿÿÿ va_end(args);

    ÿ}

    and you pass it down to oryginal slog() which also takes varargs

    void slog_(char *format, ...)
    ÿ{
    ÿÿÿÿÿ va_list args;
    ÿÿÿÿÿ va_start(args, format);
    ÿÿÿÿ int n =ÿ vsnprintf(&slog_[slog_top][0], slog_line_max, format, args);
    ÿÿÿÿÿ va_end(args);


    ÿÿÿÿslog_top++;
    }

    which in turn as uit shows passes it down to vsnprintf

    does this passing is costly?

    Pass it through a preprocessor (-E option on many compilers) to see what
    those va-macros expand to.

    As for efficiency, that will depend on compiler; some may inline such
    code for example.

    But if performing output that also involves binary to text conversion,
    that's already a bottleneck anyway.


    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From fir@3:633/10 to All on Fri Sep 11 14:15:54 2026
    bart pisze:
    On 11/09/2026 12:25, fir wrote:
    ok if someone want regular c stuff
    (there still are some parts of c i dont learned (i got no tiem as they
    vere rarely used)it is this variadic stuff

    i once seen it like maybe outdated/obsolete/archaic stuff but in fact
    i had probably normie mind in this point - becouse later i discovered
    that this printf is not such bad in practice (im not sure if i would
    name it very good but if back then i got a view that my apps shouldnt
    use it and maybe i should use my own separate routines for printing
    text and numbers it showed to be more annoying (those print("ss");
    printN(23);ÿ print("aassaaas"); ) than printf

    but im not fully comprehending this varargs stuff and i think i should
    learn it (though its panful for old 50 year old man)

    so the question is the passing down the variadic arguments costly?

    how it work?

    i mean whenÿ you got function that takes varargs like

    ÿÿvoid slog_yellow(char *format, ...)
    ÿÿ{
    ÿÿÿÿ SlogColor(0xffff00);ÿÿÿ va_list args; va_start(args, format);
    slog(format, args);ÿÿÿ va_end(args);

    ÿÿ}

    and you pass it down to oryginal slog() which also takes varargs

    void slog_(char *format, ...)
    ÿÿ{
    ÿÿÿÿÿÿ va_list args;
    ÿÿÿÿÿÿ va_start(args, format);
    ÿÿÿÿÿ int n =ÿ vsnprintf(&slog_[slog_top][0], slog_line_max, format,
    args);
    ÿÿÿÿÿÿ va_end(args);


    ÿÿÿÿÿslog_top++;
    }

    which in turn as uit shows passes it down to vsnprintf

    does this passing is costly?

    Pass it through a preprocessor (-E option on many compilers) to see what those va-macros expand to.

    As for efficiency, that will depend on compiler; some may inline such
    code for example.

    But if performing output that also involves binary to text conversion, that's already a bottleneck anyway.

    you could eventuall do that if its quick to do it for you..i may do it
    but only later...im also not only for checking but also for discussing


    (people falsely assume OFTEN (and its annoys me) that checking is the
    same or better than discussing somethin - those are two separate things, discussing gived deeper orentation/understanding)

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Lawrence D?Oliveiro@3:633/10 to All on Sun Sep 13 00:44:20 2026
    On Fri, 11 Sep 2026 13:25:03 +0200, fir wrote:

    but im not fully comprehending this varargs stuff and i think i
    should learn it (though its panful for old 50 year old man)

    Don?t worry about the internals of how it works, since that will very
    much be architecture-specific. Just learn to use it, which is
    basically quite simple. Just overlook the fact that it?s a gigantic
    hole in the safeness? of the C type system.

    One thing I have done is create Python wrappers around varargs calls
    which can indeed be fully type-safe. This can be done entirely in
    Python, without writing any C code, thanks to this wonderful library
    module for creating wrappers, called ctypes <https://docs.python.org/3/library/ctypes.html>.

    ?HAHAHA etc

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Lane W@3:633/10 to All on Sat Sep 12 18:59:48 2026
    Lawrence D?Oliveiro wrote:
    On Fri, 11 Sep 2026 13:25:03 +0200, fir wrote:

    but im not fully comprehending this varargs stuff and i think i
    should learn it (though its panful for old 50 year old man)

    Don?t worry about the internals of how it works, since that will very
    much be architecture-specific. Just learn to use it, which is
    basically quite simple. Just overlook the fact that it?s a gigantic
    hole in the safeness? of the C type system.

    One thing I have done is create Python wrappers around varargs calls
    which can indeed be fully type-safe. This can be done entirely in
    Python, without writing any C code, thanks to this wonderful library
    module for creating wrappers, called ctypes <https://docs.python.org/3/library/ctypes.html>.

    ?HAHAHA etc

    Maybe he is referring to a phenomenon I've encountered while working with C:

    It doesn't take much effort to learn a new C concept, WHEN, I need to
    use it.

    But there are lots out there and this isn't getting the job done of
    "learning the whole language", as I haven't found the call to use
    everything yet.

    Not to mention a certain drift backwards during vacations.

    Any suggestions? Perhaps just to keep pushing it even when I'm not so inclined?

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From fir@3:633/10 to All on Sun Sep 13 11:17:41 2026
    Lawrence D?Oliveiro pisze:
    On Fri, 11 Sep 2026 13:25:03 +0200, fir wrote:

    but im not fully comprehending this varargs stuff and i think i
    should learn it (though its panful for old 50 year old man)

    Don?t worry about the internals of how it works, since that will very
    much be architecture-specific. Just learn to use it, which is
    basically quite simple. Just overlook the fact that it?s a gigantic
    hole in the safeness? of the C type system.

    One thing I have done is create Python wrappers around varargs calls
    which can indeed be fully type-safe. This can be done entirely in
    Python, without writing any C code, thanks to this wonderful library
    module for creating wrappers, called ctypes <https://docs.python.org/3/library/ctypes.html>.

    ?HAHAHA etc



    ok it showed not so hard

    for example implementation of

    varar("iicffd", 1, 2, 'a', 9.f, 8.5f, 10.0);

    which may be simple implementation/interface of many cases of usage of
    this whowed to be (ai)

    #include <stdio.h>
    #include <stdarg.h>

    void varar(const char *types, ...)
    {
    va_list ap;
    va_start(ap, types);

    while(*types) {
    switch(*types) {
    case 'i': printf("%d\n", va_arg(ap, int)); break;
    case 'c': printf("%c\n", va_arg(ap, int)); break;
    case 'f': printf("%f\n", (double)va_arg(ap, double)); break;
    case 'd': printf("%f\n", va_arg(ap, double)); break; }
    types++; }

    va_end(ap);
    }

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Lawrence D?Oliveiro@3:633/10 to All on Tue Sep 15 02:41:40 2026
    On Sun, 13 Sep 2026 11:17:41 +0200, fir wrote:

    Lawrence D?Oliveiro pisze:

    One thing I have done is create Python wrappers around varargs
    calls which can indeed be fully type-safe.

    ok it showed not so hard

    for example implementation of

    varar("iicffd", 1, 2, 'a', 9.f, 8.5f, 10.0);

    This is where dynamically-typed languages have the edge.

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