🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #2089

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

#2089
From: bartc
Date: Wed, 02 Dec 2026 16:41
79 lines
4992 bytes
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).

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.

(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!)

 >      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.

 >  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.

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).

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.

Technical Details
Message-ID: <11ephnc$38pcd$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-mail
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>

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: bartc <bc@freeuk.com>
Newsgroups: comp.lang.c
Subject: Re: variadic min and max, (any some and none, cat and more)
Date: Wed, 2 Dec 2026 16:41:18 +0000
Organization: A noiseless patient Spider
Lines: 79
Message-ID: <11ephnc$38pcd$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>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 02 Dec 2026 16:41:17 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="3433869"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+snOm8ErA7eIFLujUQMAJg"; posting-host="dae4ad6537776849a7d0198fdeb00987"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:+GF9mzrD/SFyhLHq37We/cUHDMk= sha256:bGpg/p++wuZVNxlM35cXY8KOlReNYYEVMM1SfEyqExI=
	sha1:ZiD+FbP2yQ0tl0bKFd0VXSFEbUA= sha256:8aT2ZGQylpSZisi3usy13GKJzO336HJfyzH0Zy7NLWs=
In-Reply-To: <11eoj9r$2o8nc$1@dont-email.me>
Content-Language: en-GB