
printf() format-string parser wanted!
Quote:
> Folks,
> Does anyone out there have a parser to validate printf() style
^^^^^
Quote:
> statements (ie. all those that take the format string in the
> standard library) to check that the number of arguments matches
> the format-string supplied? This pre-supposes that the format
> string is a literal, naturally.
Someone else (I think it was Koenig?) already mentioned you should
try gcc, or if you live on a PC: djgpp. I would like to add that
you can easily use its checking mechanism to check format strings
in other functions: if a function has the same argument list and
return type as printf(), compile it with
#ifdef CHECK_FORMAT_STRINGS
#define your_function printf
#define another_func scanf
#endif
and don't forget to undefine CHECK_FORMAT_STRINGS when you want to
generate your executable. You could put -DCHECK_FORMAT_STRINGS in the
CFLAGS in a special makefile called, say, Makefile.check. When you
want to check, you'd run
make -f Makefile.check
You could even make a macro that you could add right below each
prototype:
#ifdef CHECK_FORMAT_STRINGS
#define FORMATLIKE(x,y) y
#else
#define FORMATLIKE(x,y) x
#endif
int your_function (char *, ...);
FORMATLIKE (your_function, printf)
Well, just a thought...
--
^^
University of Twente =x= \ tel. +31 53 893747
Tele-Informatics & Open Systems | \ tfx. +31 53 333815
P.O. Box 217 7500 AE Enschede /|__ \
The Netherlands (____)_/
Fortune's Real-Life Courtroom Quote #52:
Q: What is your name?