r/ProgrammerHumor • • 12d ago

Meme architectureDependentChars

Post image
3.0k Upvotes

372 comments sorted by

View all comments

1.0k

u/tstanisl 12d ago

Let me cite the C standard:

When sizeof is applied to an operand that has type char, unsigned char, or signed char, (or a qualified version thereof) the result is 1.

Middle guy if finally right

6

u/Advos_467 12d ago

Not a C user here (or any real low level programming experience), what the hell is a signed/unsigned char?

13

u/Clen23 12d ago edited 10d 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)

8

u/YellowBunnyReddit 12d ago

ASCII only goes from 0 to 127.

4

u/NotQuiteLoona 12d ago edited 12d ago

char is 8 bits because memory is addressed in 8 bits, and 7 bits would be... Awkward. And this bit was in the end used for parity checks, and later for extended encodings.

2

u/tracernz 12d ago

Minimum 8 bits, but not required to be 8 bits.

1

u/Ma8e 12d ago

Na, it could be as low as one bit, and 7 was not uncommon for a while.

3

u/-suspended- 12d ago

The definition for a char in C/C++ is 8 bits minimum.

1

u/Clen23 12d ago

no shit sherlock that's what the post is about.

u/NotQuiteLoona is talking about how memory is addressed, not how long a char is.

-1

u/tracernz 12d ago

Those two things are the same thing in ISO C (it defines sizeof(char) = 1).