Article View: comp.lang.c
Article #718Re: variadic min and max, (any some and none, cat and more)
From: bartc
Date: Fri, 23 Oct 2026 15:02
Date: Fri, 23 Oct 2026 15:02
59 lines
3102 bytes
3102 bytes
On 23/10/2026 13:42, fir wrote:
> David Brown pisze:
>> Variadic functions have no way of counting their arguments, or
>> identifying their types.
>
>
> this is silly becouse it cos t one register to use so its totally not a
> problem
>
>
> the case with various type arguments is much harder but the one with
> "all ints" etc is quite easy
>
>
> simpl as i said the user need the arg[] and arg_max avaliable
>
>
> foo(int ...v)
> {
> Β for(int i=0; i<sizeof(v)/sizeof(int); i++)
> {
>
> }
Yes, you can create an alternative variadic solution, that doesn't
interfere with how regular variadic functions work.
I came up with a similar idea to yours, but the parameter list looks
like this:
void F(int a, b, c ...) {}
So it is "c ..." not "c, ...". "c" is a variadic parameter, which is
passed as an int array.
I never did an implementation, but the elements would be assembled into
a buffer, not pushed, and a pointer to that buffer passed as well as the
length. (My scheme would have been syntactic sugar for slices, which
carry a length.)
Of course this is only where all variadic elements are the same type.
Mixed types would need to use the existing less safe variadic scheme.
Note that current ABIs would not support a new scheme, making it harder
to use such functions across languages and even with C implementations
that did not support it.
In this case, an API (not ABI!) exporting such a function may need to
express it in regular C terms. So for my example, it might be something
like this if a separate pointer/length args are passed.
void F(int a, b, *c, size_t clength);
Callers also wouldn't be able to do F(1, 2, 3, 4, 5), it would need to be:
F(1, 2, (int[]){3, 4, 5}, 3);
Technical Details
Message-ID:
<11bfsv1$1tdju$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-mailReferences:
<11bes8b$1gncr$1@dont-email.me> <11bf84v$1jkb5$1@dont-email.me> <11bfko4$1q1en$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: bartc <bc@freeuk.com> Newsgroups: comp.lang.c Subject: Re: variadic min and max, (any some and none, cat and more) Date: Fri, 23 Oct 2026 16:02:57 +0100 Organization: A noiseless patient Spider Lines: 59 Message-ID: <11bfsv1$1tdju$1@dont-email.me> References: <11bes8b$1gncr$1@dont-email.me> <11bf84v$1jkb5$1@dont-email.me> <11bfko4$1q1en$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Fri, 23 Oct 2026 15:02:57 +0000 (UTC) Injection-Info: dont-email.me; logging-data="2012798"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19PEGfiU5jxXDX3R1LmrRcT"; posting-host="df1406970d80d921c8a9b174013cabf0" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:AcrxYNP/5hrsVgHc0uJ8r/AbWi8= sha256:BLVLft29lqDRQmYWmb0p3AoxxeoCFpf+ee5qTJ0G3a0= sha1:7a0U/7AyVfnUAj8zs5jRkowYDR8= sha256:4OvCquS5+uNQdANrxlLasYlxhL/e4P3HkTvyRah3lis= Content-Language: en-GB In-Reply-To: <11bfko4$1q1en$1@dont-email.me>