• Re: variadic min and max, (any some and none, cat and more)

    From Rosario19@Ros@invalid.invalid to comp.lang.c on Sat Oct 31 17:33:24 2026
    From Newsgroup: comp.lang.c

    On Sun, 25 Oct 2026 04:24:26 +0000, Richard Harnden wrote:
    On 23/10/2026 06:44, fir wrote:
    when thinkong on variadic functions not much come to mind but
    only recently i noticed min or max would be good for variadic

    the ai wrote me such variadic min

    I don't think that I'd bother with stdarg at all.

    Just use a string of ints ...

    int min(const int *n)
    {
    int m = INT_MAX;

    while ( *n )
    {
    if ( *n < m ) m = *n;

    n++;
    }

    return m;
    }

    int a=Min(4,10,3,7,-2); // -2

    int a = min((int[]){10,3,7,-2}));

    in this way can not be used 0, in the 0 terminated list of integers...

    I think would be better opertate in the INT_MAX terminate list of
    integers (so the range would be INT_MIN..(INT_MAX-1)):

    int min(int *n)
    {int m=INT_MAX;

    while ( *n!=INT_MAX )
    {if ( *n < m ) m = *n;
    n++;
    }
    return m;
    }

    this would be better because allow to use 0 too at cost to not use the
    INT_MAX value

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From fir@profesor.fir@gmail.com to comp.lang.c on Sat Oct 31 18:53:09 2026
    From Newsgroup: comp.lang.c

    Rosario19 pisze:
    On Sun, 25 Oct 2026 04:24:26 +0000, Richard Harnden wrote:
    On 23/10/2026 06:44, fir wrote:
    when thinkong on variadic functions not much come to mind but
    only recently i noticed min or max would be good for variadic

    the ai wrote me such variadic min

    I don't think that I'd bother with stdarg at all.

    Just use a string of ints ...

    int min(const int *n)
    {
    int m = INT_MAX;

    while ( *n )
    {
    if ( *n < m ) m = *n;

    n++;
    }

    return m;
    }

    int a=Min(4,10,3,7,-2); // -2

    int a = min((int[]){10,3,7,-2}));

    in this way can not be used 0, in the 0 terminated list of integers...

    I think would be better opertate in the INT_MAX terminate list of
    integers (so the range would be INT_MIN..(INT_MAX-1)):

    int min(int *n)
    {int m=INT_MAX;

    while ( *n!=INT_MAX )
    {if ( *n < m ) m = *n;
    n++;
    }
    return m;
    }

    this would be better because allow to use 0 too at cost to not use the INT_MAX value



    thats quite good remark..interestingly i didnt thought of that thing
    (maybe becouse i nevef needed that, coz i dont much lik ethose
    things that have mark of end, but if some ould do indeed the value_max
    is imo better to use

    vaguelly i remember writing in commodore 64 assembly could have some convention (FF or FFFF) but i dont exactly remember
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Lawrence =?iso-8859-13?q?D=FFOliveiro?=@ldo@nz.invalid to comp.lang.c on Sun Nov 1 02:29:32 2026
    From Newsgroup: comp.lang.c

    On Sat, 31 Oct 2026 17:33:24 +0100, Rosario19 wrote:

    I think would be better opertate in the INT_MAX terminate list of
    integers (so the range would be INT_MIN..(INT_MAX-1)):

    min() should terminate on hitting INT_MIN, because any subsequent
    arguments would make no difference to the result.

    Similarly, max() should terminate on hitting INT_MAX.
    --- Synchronet 3.22a-Linux NewsLink 1.2