• pasing variadic arguments down

    From fir@profesor.fir@gmail.com to comp.lang.c on Fri Sep 11 13:25:03 2026
    From Newsgroup: comp.lang.c

    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)

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From fir@profesor.fir@gmail.com to comp.lang.c on Fri Sep 11 14:04:03 2026
    From Newsgroup: comp.lang.c

    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);-a 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-a you got function that takes varargs like

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

    -a}

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

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


    -a-a-a-aslog_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)
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From bart@bc@freeuk.com to comp.lang.c on Fri Sep 11 13:05:13 2026
    From Newsgroup: comp.lang.c

    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);-a 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-a you got function that takes varargs like

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

    -a}

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

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


    -a-a-a-aslog_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.

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From fir@profesor.fir@gmail.com to comp.lang.c on Fri Sep 11 14:15:54 2026
    From Newsgroup: comp.lang.c

    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);-a 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-a you got function that takes varargs like

    -a-avoid slog_yellow(char *format, ...)
    -a-a{
    -a-a-a-a SlogColor(0xffff00);-a-a-a va_list args; va_start(args, format); >> slog(format, args);-a-a-a va_end(args);

    -a-a}

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

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


    -a-a-a-a-aslog_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)
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Lawrence =?iso-8859-13?q?D=FFOliveiro?=@ldo@nz.invalid to comp.lang.c on Sun Sep 13 00:44:20 2026
    From Newsgroup: comp.lang.c

    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)

    DonrCOt 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 itrCOs a gigantic
    hole in the safenessrCa 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>.

    rCaHAHAHA etc
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Lane W@cactus_DAC@yahoo.com to comp.lang.c on Sat Sep 12 18:59:48 2026
    From Newsgroup: comp.lang.c

    Lawrence DrCOOliveiro 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)

    DonrCOt 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 itrCOs a gigantic
    hole in the safenessrCa 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>.

    rCaHAHAHA 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?
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From fir@profesor.fir@gmail.com to comp.lang.c on Sun Sep 13 11:17:41 2026
    From Newsgroup: comp.lang.c

    Lawrence DrCOOliveiro 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)

    DonrCOt 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 itrCOs a gigantic
    hole in the safenessrCa 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>.

    rCaHAHAHA 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);
    }
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Lawrence =?iso-8859-13?q?D=FFOliveiro?=@ldo@nz.invalid to comp.lang.c on Tue Sep 15 02:41:40 2026
    From Newsgroup: comp.lang.c

    On Sun, 13 Sep 2026 11:17:41 +0200, fir wrote:

    Lawrence DrCOOliveiro 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.
    --- Synchronet 3.22a-Linux NewsLink 1.2