Article View: comp.lang.c
Article #740Re: variadic min and max, (any some and none, cat and more)
From: Tim Rentsch
Date: Sat, 24 Oct 2026 14:17
Date: Sat, 24 Oct 2026 14:17
36 lines
2679 bytes
2679 bytes
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. Sadly the discussion that followed consisted mostly of partial ideas for how some simpler problem might be solved. Instead just implement something (in standard C, since this is comp.lang.c); it can be done in C11. Then either post a solution or explain a problem encountered during an attempted solution. Most of the comments that have been posted were just ego stroking.
Technical Details
Message-ID:
<86a4o3npy8.fsf@linuxsc.com>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>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: 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: Sat, 24 Oct 2026 07:17:03 -0700 Organization: A noiseless patient Spider Lines: 36 Message-ID: <86a4o3npy8.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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Date: Sat, 24 Oct 2026 14:17:08 +0000 (UTC) Injection-Info: dont-email.me; logging-data="2923925"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18DdXCMii7Xaz1K6Ly9rDXbIZN0vu6vhJU="; posting-host="b519dc3a4fe2decff664172eb01ae8fe" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:h8yIDjvOfQ3TpOEt0KIrLsjN0ds= sha1:VBtrqzfgyrJb3zXBnFXC+Ssawak= sha256:Fd6y7E+c3BIRys9rsTyvfAlbkyRwcbKyVRqj2mcoowk= sha1:jP7dv1URj6zEFxkHnVUQNAXZHLE= sha256:zQSW7vB8bfX5sfP+hiV3KEQEdMgI1WQn/nhkZ3P/tT0=