Reputation: 23
In Debian 8's source code /source/procps-3.3.9/lib/fileutils.c line 38 is: char const *write_error = _("write error");
I am confused about the _("write error") part. Google showed that result on variable naming convention or library reserved names, but nothing about when _ was on the right side of = and before a () quoted string.
I also put this line into a simplest test program as only useful line then had compilation failed saying:
test.c:5:20: warning: implicit declaration of function ‘_’ [-Wimplicit-function-declaration] char const *str = _("test string"); ^ test.c:5:20: warning: initialization makes pointer from integer without a cast [-Wint-conversion] /tmp/cczQpqTh.o: In function `main': test.c:(.text+0x15): undefined reference to `_' collect2: error: ld returned 1 exit status
Does anyone know what _(" ")
format means?
Upvotes: 2
Views: 135
Reputation: 399793
This is the standard way to mark up strings for translation using GNU gettext, a free software translation tool.
The _()
macro is found by an external tool which extracts the text to make it translatable, as well as (at run-time) do look-ups to replace the literal with the necessary translation.
There is nothing special about the name _
, it's just a very short but perfectly valid C identifier. Perhaps it's a bit iffy to begin a public symbol with an underscore, I'm not sure right now.
The error you're getting is because your test program very likely fails to include the <libintl.h>
header (part of gettext, of course) which declares this macro. Thus you get the normal "undefined reference" error, as expected.
Upvotes: 6