Question

i saw the following kind of code :
g_print("%s\n",_("foo"));

i haven't seen this style of passing arguments to print function ,but then i tried these :
g_print("%s\n","foo"); g_print("%s\n",("foo"));

then i thought had something to do with gtk(i'm fairly new to it) , but then i tried the same thing with printf :

printf("%s\n",_("foo")); printf("%s\n","foo"); printf("%s\n",("foo"));

and all the above do the same thing : print foo to stdout . So my question is does passing the argument as "foo" , _("foo") ,or ("foo") make any difference at all , or is any one syntactic sugar for the others,both in the case of printf , as well as g_print ?

sorry if this turns out to be a duplicate question ,but i couldn't seem to put my finger on what i should have searched for exactly in the first place .

Was it helpful?

Solution 2

You are probably seeing some sort of gettext macro, such as the one described by the glib docs. A common source for these is including glib/gi18n.h directly or (most likely) indirectly.

Marks a string for translation, gets replaced with the translated string at runtime.

That header file contains a few in this vein:

#define  _(String) gettext (String)

OTHER TIPS

The _() is actually a C macro defined as:

#define _(x) some_func(x)

Don't confuse it with ("foo") or "foo". Both of these are same and are just C strings.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top