On Thu, May 13, 2021 at 06:01:39PM -0400, Jason Merrill via Gcc wrote:
> I understand that the difference between the _ macro and the N_ macro is
> that the former is used to force a gettext call on the argument and the
> latter is used for strings for which gettext will be called later.  But I
> don't see any documentation about why/when we should use the G_ macro
> instead of one of the other two.  It seems to be used for diagnostic
> messages, for which gettext will be called in the diagnostic machinery; why
> use G_ instead of N_ in such cases?

See gcc/po/exgettext for details.
The two macros are:
# define N_(msgid) msgid
# define G_(gmsgid) gmsgid
and for exgettext the prefixes of the arguments determine the the kind
of format string:
    if (args ~ /g$/)
        format="gcc-internal-format"
    else if (args ~ /noc$/)
        format="no-c-format"
    else if (args ~ /c$/)
        format="c-format"
So, G_("...") results in the string being collected as
#, gcc-internal-format
while with N_("...") it is
", c-format
gettext has support for gcc-internal-format (though I wonder when that has
been updated last time) and for gcc diagnostic format specifiers will make
sure the translations handle that correctly.

        Jakub

Reply via email to