Article View: comp.lang.c
Article #741Re: variadic min and max, (any some and none, cat and more)
From: bartc
Date: Sat, 24 Oct 2026 15:05
Date: Sat, 24 Oct 2026 15:05
56 lines
3465 bytes
3465 bytes
On 24/10/2026 15:17, Tim Rentsch wrote: > bartc <bc@freeuk.com> writes: > > [discussing how to implement min() and max() functions] > >> [...] >> 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. > > First let's take a stab at stating the problem: > > 1. Define min() and max() variadic functions or macros ... > > 2. That accept any (reasonable) number of arguments ... > > 3. Which can be any combination of suitable types ... > > 4. Including standard integer types and real floating types ... > > 5. Evaluating each argument exactly once ... > > 6. Producing a result having a type suitable to the arguments ... > > 7. And does something sensible when arguments are of mixed types. I thought (3) implied mixed types, so that it would work even in that case. (Maybe 'suitable' needs to be defined.) But (7) suggests that would be an error. What about types such as pointers (where comparisons can work), or structs (where they don't)? Without a more vigorous spec, this is just too open-ended. > > Sadly the discussion that followed consisted mostly of partial > ideas for how some simpler problem might be solved. And what /was/ the problem? The one I concentrated on was a different way of dealing with a variable number of arguments to a function, via a hypothetical new feature. Not specifically multi-operand min/max. I did not look at how it would be done in standard C (I only suggested how a likely mechanism might be expressed in standard C, for the purpose of calling from a regular compiler, but one which would be too unwieldy to use in practice.) > Most of the > comments that have been posted were just ego stroking. Yours won't be of course!
Technical Details
Message-ID:
<11bihgg$2qcnt$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> <11bfsv1$1tdju$1@dont-email.me> <86a4o3npy8.fsf@linuxsc.com>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: Sat, 24 Oct 2026 16:05:52 +0100 Organization: A noiseless patient Spider Lines: 56 Message-ID: <11bihgg$2qcnt$1@dont-email.me> References: <11bes8b$1gncr$1@dont-email.me> <11bf84v$1jkb5$1@dont-email.me> <11bfko4$1q1en$1@dont-email.me> <11bfsv1$1tdju$1@dont-email.me> <86a4o3npy8.fsf@linuxsc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sat, 24 Oct 2026 15:05:53 +0000 (UTC) Injection-Info: dont-email.me; logging-data="2962173"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+c2JGW9IkEGEcOcxDqvL9h"; posting-host="f782badb72f356698598d4182f8e6bf9" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:qDnxmkKXILKUIsvzzHks2+gdHJI= sha256:rBuOB8paQ2t4xFFaeErcSIEbFGkOfZ4nYoDA+ui1ftk= sha1:Y2vUp8CCVnUcw9083MB39FiYDkA= sha256:sbduCyu3g/m0KromZgmFHL10ptaN/33YhIFAjIGjjuo= In-Reply-To: <86a4o3npy8.fsf@linuxsc.com> Content-Language: en-GB