On Thu, Feb 09, 2006 at 01:20:07PM +0100, Andreas Mohr wrote: > > > if (val >= max) > > > val = max; > > > > > > which can instead be expressed as > > > > > > if (val > max) > > > val = max; > > > > > > in order to cut down on both executed cycles and cache write invalidation. > > > > I am wondering if it is actually worth the effort, since it seems to > > me as if this would normally be an exception that val >= max. And > > instead of returning with an error or aborting you normalize the value. > > It probably is unlikely in several cases, but that makes it all the more a > janitorial effort ;) > It's just "unclean" to set a variable's limit if it didn't even actually > step beyond the limit, which makes this more or less a janitorial task. I wonder if we want a macro similar to min()/max(). Maybe we could write it as: limit(val, max); which could be defined as: #define limit(val, max) { \ typeof(val) _val = (val); typeof(max) _max = (max); \ if (_val > _max) _val = _max; } Thoughts?