Article View: comp.lang.c
Article #2003Re: variadic min and max, (any some and none, cat and more)
From: Tim Rentsch
Date: Mon, 30 Nov 2026 07:08
Date: Mon, 30 Nov 2026 07:08
50 lines
3076 bytes
3076 bytes
bartc <bc@freeuk.com> writes: > 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.) Right. The question is what happens when the types involved are an unusual combination, such as an unsigned long long and a float. > But (7) suggests that would be an error. No, it doesn't. "Something sensible" might be a run-time error, or just as easily "something sensible" might have a well defined rule that produces a plausible result of a plausible type. > What about types such as pointers (where comparisons can work), or > structs (where they don't)? This question is silly.
Technical Details
Message-ID:
<86wlpukd8f.fsf@linuxsc.com>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.hispagatos.org!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> <11bihgg$2qcnt$1@dont-email.me>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch <tr.17687@z991.linuxsc.com> Newsgroups: comp.lang.c Subject: Re: variadic min and max, (any some and none, cat and more) Date: Sun, 29 Nov 2026 23:08:48 -0800 Organization: A noiseless patient Spider Lines: 50 Message-ID: <86wlpukd8f.fsf@linuxsc.com> 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> <11bihgg$2qcnt$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Date: Mon, 30 Nov 2026 07:08:49 +0000 (UTC) Injection-Info: dont-email.me; logging-data="201724"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19PmDTOC9YfLdGanXWhBs2HjHS9FxLbgrg="; posting-host="14b2dabe2e9870fe799d0b4575e040c3" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:7eEMFpmzQ6hKkYYtLgrnf/qQnZ8= sha1:2nLGhIuviDRKok263LAZcx0GKYo= sha256:es/XiYANEI2+0vRA6GN0z6RAR8F1VEKRYopTJA1Vuo4= sha1:FxAAJ9+KkiZlphQIUGJE9PtRFgQ= sha256:0YbJiPXtndPpEh5HE7BdcnOkEpvAdxuRiK104H00Sf4=