bartc <b…@freeuk.com> writes:
> On 24/10/2026 15:17, Tim Rentsch wrote:
>
>> bartc <b…@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.