Article View: comp.lang.c
Article #692variadic min and max, (any some and none, cat and more)
From: fir
Date: Fri, 23 Oct 2026 05:44
Date: Fri, 23 Oct 2026 05:44
82 lines
2868 bytes
2868 bytes
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
#include <stdarg.h>
int Min(int count,...)
{
va_list args;
va_start(args,count);
```
int min=va_arg(args,int);
for(int i=1;i<count;i++)
{
int x=va_arg(args,int);
if(x<min) min=x;
}
va_end(args);
return min;
}
to use
int a=Min(4,10,3,7,-2); // -2
int b=Min(3,15,8,12); // 8
int c=Min(1,42); // 42
problem is imo this leading argument n, imo it should
just be called
min(34,34,2);
thus the variadic support probably need to change
imo it would be better if compiler would jut provide for user such things as
*arg - (or *args?) (the ram block of arguments with size sizeof(*arg))
afg[0], arg[1], arg[2] - arguments vakues
arg - pointer to *arg
arg_n - how many
possible two version of variadic should be present one is this
'unitary' when all args are same type like array of ints
and this non unitary where any arg can have a different type then
some king of typeof(arg[2]) operator should be probably
added
i guess such unitary variadic should just work close to an array
pasing (like pasing by int* for example
foo(int* arg)
{
}
but with hidden arg_n passed (not via stack probably by register, unless
arrays are overally passed with size)
and with functionality to call it in place
ike foo(2,3,4,1,3,4)
whiuch in case of things like min max could be handy
thou it need to be rethinked yet
Technical Details
Message-ID:
<11bes8b$1gncr$1@dont-email.me>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-mailShow 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: fir <profesor.fir@gmail.com> Newsgroups: comp.lang.c Subject: variadic min and max, (any some and none, cat and more) Date: Fri, 23 Oct 2026 07:44:36 +0200 Organization: A noiseless patient Spider Lines: 82 Message-ID: <11bes8b$1gncr$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Fri, 23 Oct 2026 05:44:43 +0000 (UTC) Injection-Info: dont-email.me; logging-data="1596827"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/ZUw5T16owSJIW/9uKjMo9nlkgcRhg9wc="; posting-host="43cad3fa7698c2e9be359f2072ea7249" User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:140.0) Gecko/20100101 Firefox/140.0 SeaMonkey/2.53.24 Cancel-Lock: sha1:b/x5VXvV1krMeVCXP4LaBaYvCRM= sha256:vVUXmvUHyrjLASzxnpAiN4m9Y0/uZ2yqZVQ20e1r8Ts= sha1:erGRUVBrZXMNuGUXKppn7jFH7Cc= sha256:LCkhs2Uezau3phmRMtihxFQpdvwfVx73RBkP4IbivS8= X-Mozilla-News-Host: news://news.eternal-september.org:119