7

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_

Destructor
  • 14,123
  • 11
  • 61
  • 126
Renjith G
  • 4,718
  • 14
  • 42
  • 56

3 Answers3

14

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.

Alex Cohn
  • 56,089
  • 9
  • 113
  • 307
Steve Jessop
  • 273,490
  • 39
  • 460
  • 699
4

The standard requires that the integer value of all characters required by the standard (A-Z, a-z, 0-9, basic punctuation, etc.) be positive, so any system using an encoding where these characters' values are outside the range of signed char must have plain char be unsigned. I believe this means all EBCDIC systems must have a plain char that's unsigned, but I may be mistaken.

R.. GitHub STOP HELPING ICE
  • 208,859
  • 35
  • 376
  • 711
  • 4
    If `CHAR_BIT` > 8 the range of values for `char` is greater than -128..127 or 0..255. So, on an EBCDIC system with CHAR_BIT == 9, a plain `char` can be signed. – pmg Sep 16 '10 at 18:04
2

There is usually an option to set it as default, but no compiler of my knowledge does that.

jv42
  • 8,521
  • 5
  • 40
  • 64
  • 2
    There is. In MSVC you use [`/J` (Default char Type Is unsigned)](https://msdn.microsoft.com/en-us/library/0d294k5z.aspx). In GCC you use [`-funsigned-char`](http://stackoverflow.com/a/20518559/995714) – phuclv Feb 20 '16 at 03:29