🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #721

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

#721
From: Ike Naar
Date: Fri, 23 Oct 2026 16:47
28 lines
2198 bytes
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.
>
> If the sentinel value were changed to INT_MAX the none-match requirement
> can be dropped (since INT_MAX is the identity element of the min operation
> it could safely appear in the argument list).

Sorry, I was not thinking things through. Please forget that post.
Technical Details
Message-ID: <slrn11dn3tb.m3u.ike@iceland.freeshell.org>
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> <11bf84v$1jkb5$1@dont-email.me> <slrn11dn3gq.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: Ike Naar <ike@sdf.org>
Newsgroups: comp.lang.c
Subject: Re: variadic min and max, (any some and none, cat and more)
Date: Fri, 23 Oct 2026 16:47:40 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 28
Message-ID: <slrn11dn3tb.m3u.ike@iceland.freeshell.org>
References: <11bes8b$1gncr$1@dont-email.me> <11bf84v$1jkb5$1@dont-email.me>
 <slrn11dn3gq.m3u.ike@iceland.freeshell.org>
Injection-Date: Fri, 23 Oct 2026 16:47:41 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="2073540"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1/Saurz/Smp67xV4el2hA0j"; posting-host="0b661e8b0a569d4fc4ff0910fe9e12ef"
User-Agent: slrn/1.0.3 (Patched for libcanlock3) (NetBSD)
Cancel-Lock: sha1:x/wtfjdjWJCJaN8mNCWR033o88g= sha256:qaFO6KgFSKBsTcRviIwZoPtZ/q6SdoIHiwEJ6pBdLH8=
	sha1:lNfw0oYAitO7JYDQIJupfFHYmDw= sha256:0EqyMKLYRFeFRekOefLsbyL7rb27nAAJf7y4a2nDIVg=