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?
Asked
Active
Viewed 157 times
2

Community
- 1
- 1

Igor Liferenko
- 1,499
- 1
- 13
- 28
-
Don't. :) You're asking for problems. Good question though. – Qix - MONICA WAS MISTREATED Nov 16 '16 at 07:34
-
When I said 'wrap' I meant to write a new wrapper function such as `ToUpper()` that calls through to `toupper()`, and change your code to call the wrapper. Then you can add your own code inside the wrapper to fix just about anything. It's a good general policy. – david.pfx Nov 20 '16 at 23:56
1 Answers
3
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.

chqrlie
- 131,814
- 10
- 121
- 189
-
How to make char unsigned by default without using `-funsigned-char` gcc option? I don't want to type each time, or create aliases and stuff. I just want to use the command `gcc` and have this behavior by default. Maybe there is a config file or a pragma to be put directly into a program? – Igor Liferenko Nov 18 '16 at 08:22
-
Why argument type of `putchar()`, `fputc()` and `putc()` is not `char`, but argument type of `putwchar()`, `fputwc()` and `putwc()` is `wchar_t`? Also, why in example from man `mbstowcs` the variable of type `wchar_t` is passed to `iswlower()` ? This contradicts to the fact that `iswlower()` takes `wint_t`. Is the example wrong? – Igor Liferenko Nov 18 '16 at 08:32
-