[Bro-Dev] min() and max() problem in util.h

Robin Sommer robin at icir.org
Wed Nov 24 08:06:43 PST 2010


On Wed, Nov 24, 2010 at 07:38 -0800, you wrote:

> One could write a bunch of overloaded min/max function to handle all
> kinds of argument types correctly.

Actually I think that's the best solution, and I don't really see
how it would cause hard to find bugs? min/max seems simple enough,
and as long as we don't provide versions with mixed argument types,
I think we should be fine. Or am I missing something nasty?

>    min_i32(), min_u32(), min_u64(), min_64()....

That looks pretty ugly, in particualr when overloading can solve the
problem automatically. 

> Or, I can just replace the min/max function with a macro.

I'd expect that to actually generate more bugs than the overloading.

On Wed, Nov 24, 2010 at 07:51 -0800, you wrote:

> GCC's typeof() extension can solve this, however, then we'd have
> compiler dependent code :-(

Yeah, not good. 

Robin

-- 
Robin Sommer * Phone +1 (510) 722-6541 * robin at icir.org
ICSI/LBNL    * Fax   +1 (510) 666-2956 *   www.icir.org



More information about the bro-dev mailing list