[coreboot] libpayload: Convert HEX2BIN/BIN2HEX to functions, add abs() et al

Uwe Hermann uwe at hermann-uwe.de
Tue Apr 8 12:49:12 CEST 2008

Updated patch with comments merged. Added doxygen comments, and
hex2bin() now also supports upper-case characters.

On Tue, Apr 08, 2008 at 08:54:40AM +0200, Segher Boessenkool wrote:
>> Do we really need all the types?  I think that we can get by

Dunno, I just needed an abs(), but when looking at the manpage I also
saw that labs() and llabs() are part of a standard libc so I thought
I might as well just add them too.

>> 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.

> 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
> evaluation.

What fix do you propose? Is there a way to improve the macro or
do you suggest to  leave the code as a function?

http://www.hermann-uwe.de  | http://www.holsham-traders.de
http://www.crazy-hacks.org | http://www.unmaintained-free-software.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: libpayload_abs_hexbin2.patch
Type: text/x-diff
Size: 2688 bytes
Desc: not available
URL: <http://www.coreboot.org/pipermail/coreboot/attachments/20080408/b7c44567/attachment.bin>

More information about the coreboot mailing list