Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any compiler which takes 'char' as 'unsigned' ?

Is there any C compiler which takes the default type of char as unsigned unless explicitly mentioned by the user in the file or project settings?

/Kanu_

like image 300
Renjith G Avatar asked Sep 16 '10 15:09

Renjith G


People also ask

Can char be unsigned?

unsigned char is a character datatype where the variable consumes all the 8 bits of the memory and there is no sign bit (which is there in signed char). So it means that the range of unsigned char data type ranges from 0 to 255.

Is char unsigned or signed C++?

The C and C++ standards allows the character type char to be signed or unsigned, depending on the platform and compiler. Most systems, including x86 GNU/Linux and Microsoft Windows, use signed char , but those based on PowerPC and ARM processors typically use unsigned char .

Is char default signed or unsigned?

In the book "Complete Reference of C" it is mentioned that char is by default unsigned.

Is a char an unsigned byte?

An unsigned char is an unsigned byte value (0 to 255). You may be thinking of char in terms of being a "character" but it is really a numerical value. The regular char is signed, so you have 128 values, and these values map to characters using ASCII encoding.


1 Answers

GCC does. But only when compiling for platforms where an unsigned char is the convention, including ARM linux[*]. When GCC compiles for x86, the default is for char to be signed.

[*] Or at least it has been in the past. For all I know linux has switched to a different default ABI on ARM since.

Update '2013: ARM compilers (gcc, clang) for Android NDK default to unsigned char. The x86 and MIPS compilers default to signed char.

like image 118
Steve Jessop Avatar answered Sep 21 '22 21:09

Steve Jessop