如何包装glibc库函数以自动使用'unsigned char'和'wchar_t'? [英] How to wrap glibc library functions to automatically use 'unsigned char' and 'wchar_t'?
问题描述
我总是将char
用作unsigned char
,将wchar_t
用作wint_t
.鉴于此,是否存在解决方案来更改功能接口以使用这些类型而无需重新编译glibc?另请参阅以下问题:
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?
推荐答案
您可以将命令行选项传递给编译器,以使char
默认为无符号.通过使用宏和typedef重新定义char
来将接口更改为标准库功能不是实现目标的正确方法.
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.
对于gcc和clang,请使用-funsigned-char
.
For gcc and clang, use -funsigned-char
.
对于Visual C ++,请使用-J
或/J
.
For Visual-C++, use -J
or /J
.
宽字符类型wchar_t
是特定于系统的,在Linux系统上以及使用glibc的任何地方通常为32位宽,但是出于历史原因,对于Microsoft工具只有16位宽.更改此类型将导致编译器与库之间的兼容性问题,甚至不用考虑它.
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.
这篇关于如何包装glibc库函数以自动使用'unsigned char'和'wchar_t'?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!