Since the nature of a char
in C++ is compiler-dependent when the unsigned
qualifier is not present, is there an argument I could pass on to GCC which would force all char
s to be compiled as unsigned
?
The flag you are looking for is -funsigned-char
.
From the documentation:
-funsigned-char
Let the type
char
be unsigned, likeunsigned char
.Each kind of machine has a default for what
char
should be. It is either likeunsigned char
by default or likesigned char
by default.Ideally, a portable program should always use
signed char
orunsigned char
when it depends on the signedness of an object. But many programs have been written to use plainchar
and expect it to be signed, or expect it to be unsigned, depending on the machines they were written for. This option, and its inverse, let you make such a program work with the opposite default.The type
char
is always a distinct type from each ofsigned char
orunsigned char
, even though its behavior is always just like one of those two.
-fsigned-char
Let the type
char
be signed, likesigned char
.Note that this is equivalent to
-fno-unsigned-char
, which is the negative form of-funsigned-char
. Likewise, the option-fno-signed-char
is equivalent to-funsigned-char
.
This only impacts char
; types like wchar_t
are unaffected.