Article View: comp.lang.c
Article #733Re: variadic min and max, (any some and none, cat and more)
From: David Brown
Date: Sat, 24 Oct 2026 10:59
Date: Sat, 24 Oct 2026 10:59
28 lines
2305 bytes
2305 bytes
On 23/10/2026 18:47, Ike Naar wrote:
> On 2026-10-23, Ike Naar <ike@sdf.org> wrote:
>> On 2026-10-23, David Brown <david.brown@hesbynett.no> wrote:
>>> If I wanted to write such a variadic minimum function, I would do so
>>> using a sentinel, with a macro to add the sentinel:
>>>
>>> #define SENTINEL INT_MIN
>>> #define min(x0, ...) min_func(x0 __VA_OPT__(,) __VA_ARGS__, SENTINEL)
>>>
>>> int min_func(int x0, ...) {
>>> va_list args;
>>> va_start(args);
>>>
>>> int m = x0;
>>> while (true) {
>>> int x = va_arg(args, int);
>>> if (x == SENTINEL) return m;
>>> if (x < m) m = x;
>>> }
>>> }
>>>
>>> It is up to the user to ensure that the arguments to "min" are all ints,
>>> and none of them match the sentinel value.
>>
> Sorry, I was not thinking things through. Please forget that post.
What post? :-)
Technical Details
Message-ID:
<11bi332$2jjto$4@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> <slrn11dn3gq.m3u.ike@iceland.freeshell.org> <slrn11dn3tb.m3u.ike@iceland.freeshell.org>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: David Brown <david.brown@hesbynett.no> Newsgroups: comp.lang.c Subject: Re: variadic min and max, (any some and none, cat and more) Date: Sat, 24 Oct 2026 12:59:46 +0200 Organization: A noiseless patient Spider Lines: 28 Message-ID: <11bi332$2jjto$4@dont-email.me> References: <11bes8b$1gncr$1@dont-email.me> <11bf84v$1jkb5$1@dont-email.me> <slrn11dn3gq.m3u.ike@iceland.freeshell.org> <slrn11dn3tb.m3u.ike@iceland.freeshell.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sat, 24 Oct 2026 10:59:47 +0000 (UTC) Injection-Info: dont-email.me; logging-data="2740152"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+B60bU46bqq0w66H9uMKPEla36Fje3GNY="; posting-host="16333889e06bc3a8363fafc6fb472ed9" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:lciZb4ToijJfmJKEm/8Jh6LJqAg= sha256:HInjvVpi63jiGcv0EnlWG90D3JCPJBnW86+K39mG1HU= sha1:C/M6oBylhN3TYmcpGr5HPq6thow= sha256:i0qR7NKXy6fyS5Na5rdxbCkZox0GtkjKyvE8b677UM4= Content-Language: en-GB In-Reply-To: <slrn11dn3tb.m3u.ike@iceland.freeshell.org>