[ccan] [PATCH] minmax: New module
David Gibson
david at gibson.dropbear.id.au
Mon Jun 2 22:37:57 EST 2014
On Mon, Jun 02, 2014 at 12:54:05PM +0930, Paul 'Rusty' Russell wrote:
> 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.
Ah. Excellent point.
> 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.
Ok, new version coming, requiring statement expressions and typeof.
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.ozlabs.org/pipermail/ccan/attachments/20140602/eedaea01/attachment.sig>
More information about the ccan
mailing list