What does _ ("text") do, i.e. Underscore char, do?

In C code, I came across this bit

_("test")

What is he doing? (I tried to see it myself, but, as you can imagine, search engines do not support finding this ...)

+5
source share
1 answer

It calls a function with a name _. For instance:

#include <stdio.h>

void _(int a) {
    printf("%d",a);
}
int main(void) {
         _(3);
        return 0;
}

_is an existing function in gettext library and is used for internationalization. As said in this answer This function basically replaces the given string on runtime with a translation in the system language, if available (i.e. if they shipped a .mo file for this language with the program).

+7
source

All Articles