Article View: comp.lang.c
Article #2091Re: variadic min and max, (any some and none, cat and more)
From: David Brown
Date: Wed, 02 Dec 2026 17:03
Date: Wed, 02 Dec 2026 17:03
116 lines
6643 bytes
6643 bytes
On 02/12/2026 17:41, bartc wrote:
>
> On 02/12/2026 08:02, David Brown wrote:
> > On 01/12/2026 22:09, bartc wrote:
> >> On 01/12/2026 20:25, David Brown wrote:
> >> It's just a scale factor. The result is a generic FP type.
> >>
> >> I have looked into properly implementing units, where multiplying tgwo
> >> length types for example gives you an area type, and where area +
> >> length is not allowed, but it very quickly gets out of hand and turns
> >> into a can of works.
> >>
> >> In any case it requires a much stricter, and hierarchical, type
> >> system, such as you might find in Ada, and may be possible in C++.
> >>
> >
> > It does not require hierarchical types (there are no type hierarchies
> > and inheritance needed), but it does require users to be able to make
> > their own types and define overloaded operators on them between
> > different types, and their own conversion functions, to be user-
> friendly.
>
> If you look at the Ada type chart, there is a kind of hierarchy (eg.
> real (float) types are a subset of scalars).
I am not an Ada expert (I know a little of it, but not much). You are
talking here about a different kind of type hierarchy than I was
thinking about, but still it is not necessary for this kind of thing.
(However, some kind of hierarchy, inheritance, mixins, templates, etc.,
can reduce boilerplate and duplication of code.)
>
> But what I was thinking of is that a Length type for example would be
> based on top of a generic Float type, and would inherit some of its
> characteristics.
Okay, yes.
>
> (And, somebody might define new types on top of Length which represent
> different length applications, that they don't want to mix.)
>
>
> > C can provide the strong and strict types (using structs), but not the
> > overloads. So in C, you can end up with :
> >
> > Acceleration a = Acceleration_C(9.81);
> > Time t = read_clock();
> > Distance d = mult(mult(0.5, a), mult(t, t));
> >
> > ("mult" here would be a _Generic macro.)
> >
> > while in C++ you can have :
> >
> > Acceleration a { 9.81 }; // or auto a = 9.81_m_p_ss
>
> (It used to be 9.82 when I was at school; gravity must have changed!)
I know you are no spring chicken, but g has been standardised at 9.80665
since 1901 :-) Of course the real value varies around the world, and it
could well be 9.82 at your school.
>
> > Time t = read_clock();
> > Distance d = 0.5 * a * t * t;
> >
> > So this /can/ be done in C, but it is much more cumbersome to define,
> > less scalable (you will want to generate the _Generic macros in some
> > way, rather than writing them by hand!) and the result is ugly.
> >
> > Most importantly, however, you need the language to support defining
> > these types and operators yourself. Adding support for lengths and
> > times might be okay in the language itself, but imagine trying to add /
> > all/ SI units to the compiler.
>
> My point about Frink is that it is futile to add them to a language no
> matter how it's done, unless you are implementing Frink.
It is fine to add them to programs and to libraries - but futile to try
to put them into a language itself.
>
> > And even then, someone will come along
> > that wants to measure speed in feet per nanosecond. (Award yourself a
> > pat on the back if you know who that might be!)
>
> I can't think who that might be, however I can see the attraction of a
> 'normalised' measure of velocity that is always within 0 and 1.
Grace Hopper, one of the pioneers of programming. And yes, the point of
feet per nanosecond is that the speed of light is almost exactly 1.
>
> But, AFAIK that's not how such units would work. With my Length example,
> the quantity stored would used a fixed unit (probably metres for SI).
Indeed, that's what you usually do - SI units with floating point. But
you should be able to set and access the units with different scales,
such as 1_m + 20_cm == 1200_mm, including non-SI units. (Clearly no
list or library will support everything.)
>
> So you could add two lengths knowing they used the same unit. If one
> length uses cm and another furlongs, then it would get a LOT more
> complicated.
>
> To keep it simple, velocity would always be metres/second say, and any
> other denotations for UI purposes would be done via conversions.
>
The underlying storage is usually SI units, but access does not have to be.
Look at TeX and LaTeX. Distances there can be given in points, mm,
inches, and various other units - the actual values are stored as 32-bit
integers scaled with 65536 units is one point.
Technical Details
Message-ID:
<11epj0j$39h1k$1@dont-email.me>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu.MISMATCH!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!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> <11ek7b2$j8f6$1@raubtier-asyl.eternal-september.org> <11ekfu0$mq5n$4@dont-email.me> <11ekg71$n5p7$1@raubtier-asyl.eternal-september.org> <11ekgf8$mq5n$8@dont-email.me> <11ekjsp$pmch$2@raubtier-asyl.eternal-september.org> <11ekq4q$snda$1@dont-email.me> <11em45u$1fp0a$1@dont-email.me> <11emdhn$1ko8h$1@dont-email.me> <11emjh1$1ntap$1@dont-email.me> <11en1a0$1vqc1$1@dont-email.me> <11enagh$24n1m$2@dont-email.me> <11end36$26j38$1@dont-email.me> <11eoj9r$2o8nc$1@dont-email.me> <11ephnc$38pcd$1@dont-email.me>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu.MISMATCH!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!news.hispagatos.org!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: Wed, 2 Dec 2026 18:03:15 +0100 Organization: A noiseless patient Spider Lines: 116 Message-ID: <11epj0j$39h1k$1@dont-email.me> References: <11bes8b$1gncr$1@dont-email.me> <11ek7b2$j8f6$1@raubtier-asyl.eternal-september.org> <11ekfu0$mq5n$4@dont-email.me> <11ekg71$n5p7$1@raubtier-asyl.eternal-september.org> <11ekgf8$mq5n$8@dont-email.me> <11ekjsp$pmch$2@raubtier-asyl.eternal-september.org> <11ekq4q$snda$1@dont-email.me> <11em45u$1fp0a$1@dont-email.me> <11emdhn$1ko8h$1@dont-email.me> <11emjh1$1ntap$1@dont-email.me> <11en1a0$1vqc1$1@dont-email.me> <11enagh$24n1m$2@dont-email.me> <11end36$26j38$1@dont-email.me> <11eoj9r$2o8nc$1@dont-email.me> <11ephnc$38pcd$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Wed, 02 Dec 2026 17:03:16 +0000 (UTC) Injection-Info: dont-email.me; logging-data="3458100"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18+/X8w9b3j+GfRbUvtyhVeU8pVMlLkK5A="; posting-host="8f689f606fabca0b227a4c433cd7c78e" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:7eHubmVmAwrw4QGtJfezzBi7RtM= sha256:h4juObh/jh4396sZ5ybkv7YBMEbb0xXWQ9O8vI09uQU= sha1:yB5DjcxSYxTsUloSwGbAYm4k6Bk= sha256:IPDvkZN0KzPYx3SGyjDbxyQJD7619F+ZmDQrjA6Aidc= In-Reply-To: <11ephnc$38pcd$1@dont-email.me> Content-Language: en-GB, nb-NO