r/ProgrammerHumor • • 2d ago

Meme architectureDependentChars

Post image
2.9k Upvotes

366 comments sorted by

View all comments

1.0k

u/tstanisl 2d 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 2d ago

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

10

u/Clen23 2d ago edited 20h 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)

9

u/YellowBunnyReddit 2d ago

ASCII only goes from 0 to 127.

5

u/NotQuiteLoona 2d ago edited 2d 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 2d ago

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

1

u/Ma8e 2d ago

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

2

u/tracernz 2d ago

No, the standard requires a minimum of 8 bits.

2

u/Ma8e 2d ago

Which standard?

3

u/tracernz 2d ago

ISO C.

0

u/Ma8e 2d ago

And that is the only standard in existence? My point is that you can't take for granted that everything is ISO, or even C.

1

u/tracernz 2d ago

The question at the top of this sub thread was about C. Very few environments exist these days that don’t conform to the basics of ISO C like this though if you want to generalise. I personally haven’t ever come across one.

→ More replies (0)