[coreboot] libpayload: Convert HEX2BIN/BIN2HEX to functions, add abs() et al
segher at kernel.crashing.org
Tue Apr 8 13:26:18 CEST 2008
>>> with just abs(), and probably even make it a #define which will
>>> eliminate the need for type checking anyway.
> Maybe, but then we could also make the other mini-functions macros
> again, e.g. bin2hex() or most of libc/ctype.c or libc/string.c for
> example. I think the usual case should be to make small functions
> instead of macros.
Even if you want this inlined (and you don't), you can keep it
a function -- make it "static inline" and put it in the header file.
But you really don't want to, it will increase code size.
For the abs() stuff you might want it though, dunno. I doubt it
would matter for speed reasons.
>> Only if you are really careful and make it a statement expression...
>>> #define abs(_a) ((_a) >= 0 ? (_a) : -(_a))
>> ...since this version ("the obvious version") suffers from double
> What fix do you propose? Is there a way to improve the macro or
> do you suggest to leave the code as a function?
Leave it as a function. If you _have_ to have it a macro, make it
a statement expression (that's a GCC extension, read the Fine Manual --
More information about the coreboot