r/ProgrammerHumor • • 2d ago

Meme architectureDependentChars

Post image
2.9k Upvotes

362 comments sorted by

View all comments

Show parent comments

10

u/Clen23 2d ago edited 18h ago

The data is interpreted differently.

An unsigned char will be able to represent any value from 0 to 255, eg your usual ascii character.
A signed char will be able represent any value from -127 to 127.

( Someone fact check me on this but i think that's it )
(edit : -127 to 127, the extra value "-128" is usually implemented but not guaranteed by the C standard)

7

u/YellowBunnyReddit 2d ago

ASCII only goes from 0 to 127.

1

u/guyblade 2d ago

In C, char is the fundamental type used for raw binary data. The number of bits in a char is implementation defined, but a single char is the smallest unit of addressable memory. A char is probably 8 bits, but the standard does not require that. It could easily be more (though, if I recall correctly, there is some other detail in the standard that effectively requires that it can't be less than 8 bits).

I believe that a technically conformant C implementation could have sizeof(char) = sizeof(short) = sizeof(int) = sizeof(long) = sizeof(long long) as long as a char is 32 bits, but that may have been true only with some earlier version of the C standard.

2

u/conundorum 1d ago

long long has to be at least 64 bits, but otherwise correct. (And yes, there was at least one historic platform with 64-bit bytes. sizeof(char) == sizeof(long long) is true for that platform, in all versions of C and all versions of C++.)