[ccan] [PATCH] minmax: New module

Rusty Russell rusty at rustcorp.com.au
Mon Jun 2 13:24:05 EST 2014


David Gibson <david at gibson.dropbear.id.au> writes:
> Add a 'minmax' module with typesafe macros to compute minimum, maximum and
> clamping.  Inspired by the versions used in the Linux kernel, but using
> a different implementation based on __builtin_types_compatible_p() and the
> cast module.

The reason I never implemented this is because I was worried about
idempotency failure.  Your functions double-evaluate, which bad form
even if they were named MIN and MAX and thus clearly macros.

Unfortunately it's not possible to create an idempotent min or max
without gcc extensions which operates on 64 bit types (or whatever the
largest integer type is).

It wouldn't be the first module which had preconditions, however:
we could create a module which simply doesn't compile if you don't have
statement expressions.

Cheers,
Rusty.


More information about the ccan mailing list