How to wrap glibc library functions to automatically use 'unsigned char' and 'wchar_t'?

时光毁灭记忆、已成空白 提交于 2019-12-11 01:55:29

问题


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.



来源:https://stackoverflow.com/questions/40626189/how-to-wrap-glibc-library-functions-to-automatically-use-unsigned-char-and-wc

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!