On Monday 25 May 2009 22:02:47 Tom Lane wrote:
> The issue of double translation is really a minor point; what is
> bothering me is that we've got such an ad-hoc,
> non-compile-time-checkable approach here. Zdenek's discovery
> today that some of the format strings are flat-out wrong
> http://archives.postgresql.org/pgsql-hackers/2009-05/msg00946.php
> surprises me not in the least.
See response there why this is the way it is.
Note also that gcc's format argument checking can see through ngettext() quite
well, so as far as I can tell, we are not exposed to accidental format string
mismatches.
Example code:
#include <stdarg.h>
#include <stdio.h>
#include <libintl.h>
extern void errmsg(const char *fmt, ...) __attribute__((format(printf,1,2)));
void
errmsg(const char *fmt, ...)
{ va_list ap;
va_start(ap, fmt); vfprintf(stderr, fmt, ap); va_end(ap);
}
int
main(int argc, char *argv[])
{ errmsg(ngettext("got %d argument, namely %s\n", "got %d arguments, first ist %s\n",
argc), argc, argv[0]); return 0;
}
I tried throwing various kinds of subtle garbage into the errmsg/ngettext
line, but it was all discovered by gcc -Wall.