In C, there are unsigned and signed integers:
int test_1 = 42;test_1 = -42; // It's ok; int is signed
An int is always signed, and so are short, long and long long. So writing signed int and int is the same thing, just two spellings.
The only exception is char. Whether char is signed or unsigned is up to the compiler. For example: signed on x86 and Apple Silicon, unsigned on ARM Linux. In C and C++ char, signed char and unsigned char are three different types, even though char always has the representation of one of the other two.
This is unique to char. For every other integer type, signed X and X are the same type (signed int is int).
Let’s look at a brief example of what this means. We’ll use C’s _Generic.
<stdint.h> <stdio.h>// Only "char" is listed. TYPE_NAME_SHORT(X)// All three character types are listed. TYPE_NAME(X)int main(void) { char c = 'a'; signed char sc = 'a'; unsigned char uc = 'a'; int8_t i8 = 'a'; printf("char only: %s, %s, %s, %s\n", TYPE_NAME_SHORT(c), TYPE_NAME_SHORT(sc), TYPE_NAME_SHORT(uc), TYPE_NAME_SHORT(i8)); printf("all entries: %s, %s, %s, %s\n", TYPE_NAME(c), TYPE_NAME(sc), TYPE_NAME(uc), TYPE_NAME(i8)); return 0;}
Output:
char only: char, no match, no match, no matchall entries: char, signed char, unsigned char, signed char
The int8_t value misses the char entry and is caught by signed char. Adding an int8_t entry next to signed char is rejected:
error: type 'int8_t' (aka 'signed char') ingeneric association compatible with previouslyspecified type 'signed char'
See Attractor PR 13 for context.
Until next time.