🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #1210

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

#1210
From: Rosario19
Date: Sat, 31 Oct 2026 16:33
47 lines
2282 bytes
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
Technical Details
Message-ID: <i06cel5b0c5rllrhc4cc1c8gld5ovgvj6u@4ax.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
References: <11bes8b$1gncr$1@dont-email.me> <11bk09r$3acgl$1@dont-email.me>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From: Rosario19 <Ros@invalid.invalid>
Newsgroups: comp.lang.c
Subject: Re: variadic min and max, (any some and none, cat and more)
Date: Sat, 31 Oct 2026 17:33:24 +0100
Organization: A noiseless patient Spider
Lines: 47
Message-ID: <i06cel5b0c5rllrhc4cc1c8gld5ovgvj6u@4ax.com>
References: <11bes8b$1gncr$1@dont-email.me> <11bk09r$3acgl$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 31 Oct 2026 16:25:27 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="1332141"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18zx+HIlX+CpdHf6zievd85vrRxVDt35KI="; posting-host="16b6d0dc3bfca910e87f2c3e3067af6e"
Cancel-Lock: sha1:UQUrGfF0jnDynbAHcKKvbs8EX0Y= sha256:LMeIxbEvvOuLpb+m8gjWK7G8Ye/lCeGVuKcrA3ILbi0=
	sha1:lX6w1wmPuu58lPqmGcS0v3JSa4U= sha256:hr+0jqJWhBGiMsy8mgpRzjj/QJvDZRoFqMcVVGe4XFg=
X-Newsreader: Forte Free Agent 1.93/32.576 English (American)