intl patches (21)

Bruno Haible haible@ilog.fr
Mon Jul 23 06:18:00 GMT 2001


The declarations of ngettext(), dngettext(), dcngettext() cause a GCC
compiler warning for the following piece of valid code:

=============================== foo.c ===============================
#include <libintl.h>
#include <locale.h>
#include <stdio.h>

void foo (int n)
{
  printf (ngettext ("a piece of cake", "%d pieces of cake", n), n);
  printf (dngettext ("foo", "a piece of cake", "%d pieces of cake", n), n);
  printf (dcngettext ("foo", "a piece of cake", "%d pieces of cake", n,
                      LC_MESSAGES),
          n);
}
=====================================================================

$ gcc -S -Wall foo.c
foo.c: In function `foo':
foo.c:7: warning: too many arguments for format
foo.c:8: warning: too many arguments for format
foo.c:11: warning: too many arguments for format

But since the msgid1 is used only for the English singular form, i.e. when
n == 1, it is customary to omit the %d representation from this format string.
The printf call should be checked against msgid2, the plural form,
instead. With the patch below, the above code compiles without warnings.


2001-07-22  Bruno Haible  <haible@clisp.cons.org>

	* intl/libintl.h (ngettext, dngettext, dcngettext): Use msgid2, not
	msgid1, for printf format argument checking.

*** glibc-20010626/intl/libintl.h.bak	Sat Oct 21 23:57:05 2000
--- glibc-20010626/intl/libintl.h	Sun Jul 22 13:54:00 2001
***************
*** 53,72 ****
     number N.  */
  extern char *ngettext (__const char *__msgid1, __const char *__msgid2,
  		       unsigned long int __n)
!      __THROW __attribute_format_arg__ (1);
  
  /* Similar to `dgettext' but select the plural form corresponding to the
     number N.  */
  extern char *dngettext (__const char *__domainname, __const char *__msgid1,
  			__const char *__msgid2, unsigned long int __n)
!      __THROW __attribute_format_arg__ (2);
  
  /* Similar to `dcgettext' but select the plural form corresponding to the
     number N.  */
  extern char *dcngettext (__const char *__domainname, __const char *__msgid1,
  			 __const char *__msgid2, unsigned long int __n,
  			 int __category)
!      __THROW __attribute_format_arg__ (2);
  
  
  /* Set the current default message catalog to DOMAINNAME.
--- 53,72 ----
     number N.  */
  extern char *ngettext (__const char *__msgid1, __const char *__msgid2,
  		       unsigned long int __n)
!      __THROW __attribute_format_arg__ (2);
  
  /* Similar to `dgettext' but select the plural form corresponding to the
     number N.  */
  extern char *dngettext (__const char *__domainname, __const char *__msgid1,
  			__const char *__msgid2, unsigned long int __n)
!      __THROW __attribute_format_arg__ (3);
  
  /* Similar to `dcgettext' but select the plural form corresponding to the
     number N.  */
  extern char *dcngettext (__const char *__domainname, __const char *__msgid1,
  			 __const char *__msgid2, unsigned long int __n,
  			 int __category)
!      __THROW __attribute_format_arg__ (3);
  
  
  /* Set the current default message catalog to DOMAINNAME.



More information about the Libc-alpha mailing list