2012
07.06

Today morning I was reviewing some small bit of code, which surprisingly compiled on i386 target just fine, but failed for ARM target. As always, the first thing I though was “Oh no! That could be variadic function!” and I was right, again.

But this time I was really surprised. The author of the code started just right fine:

#include <stdarg.h>
[...]

char * STDARGS GetKeyWord(int value, char *def, ...)
{
    [...]
    va_list va;
    [...]
    va_start(va, def);

And then, out of sudden, the motivation for using stdarg passes away, va is casted to a LONG * type and varargs handled manually. Why oh why? Why the coder uses tons of casting, where he could use a simple va_arg? Why string = *((char **) args) instead of string=va_arg(va, char *)? Why advancing the args pointer? Where is the missing va_end? I don’t know and I think I will never understand that.

Comments are closed.