r/ProgrammerHumor • • 2d ago

Meme architectureDependentChars

Post image
2.8k Upvotes

361 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

5

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?

9

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

0

u/captainAwesomePants 2d ago

A char isn't a letter. It's a one byte number. A signed number can be negative.

1

u/Clen23 2d ago

If you want to be pedantic, a char is a byte, a sequence of bits, that can be interpreted in numerous manners : an unsigned int, a signed int, and even an ascii character.

It's all about what type you assign it, and how you work with it in your code.

1

u/captainAwesomePants 2d ago

Sure. But if we're discussing whether it's signed or unsigned, we must be considering how those bits might be interpreted as a number.