How to wrap glibc library functions to automatical

2019-07-08 10:51发布

问题:

I always use char as unsigned char and wchar_t as wint_t. Given that, does there exist a solution to change function interfaces to use those types with or without recompiling glibc? See also this question: How to change wchar.h to make wchar_t the same type as wint_t?

回答1:

You can pass a command line option to the compiler to make char unsigned by default. Changing the interface to standard library functions by redefining char with macros and typedefs is not the correct way to achieve your goal.

For gcc and clang, use -funsigned-char.

For Visual-C++, use -J or /J.

The wide character type wchar_t is system specific, it typically 32-bit wide on linux systems and wherever the glibc is used, but only 16-bit wide for the Microsoft tools for historical reasons. Changing this type will cause compatibility problems between the compiler and the libraries, don't even think about it.



标签: c glibc