g_print replaces non-ascii characters with question mark
The following program:
#include <glib.h>
gint main() {
g_print("%s\n", "ä");
return 0;
}
prints "?" to standard output on debian bullseye (GLib 2.66.8). Using printf
instead of g_print
prints "ä" instead. The documentation doesn't mention any relevant differences between g_print
and printf
so I assumed they would behave the same in this program.
The reason this happens was pointed out in issue #1937 (closed) (and #1270 (closed)). g_print
converts the input to the encoding specified by g_get_charset()
before printing it, and g_get_charset
returns "ANSI_X3.4-1968" (i.e. ASCII) if setlocale
hasn't been called. But I don't know why g_print
needs to convert its input at all. printf
doesn't do that, "%s" just outputs the bytes that are passed in.
If the g_print
behaviour is considered correct, I think the documentation should mention that it performs this conversion.