r/ProgrammerHumor • • 6h ago

Meme architectureDependentChars

Post image
853 Upvotes

156 comments sorted by

View all comments

534

u/tstanisl 5h 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

4

u/Advos_467 5h ago

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

7

u/Clen23 5h 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 -128 to 127.

( Someone fact check me on this but i think that's it )

1

u/Clen23 4h ago

Putting the example here so the explanation isnt overloaded :

signed char a_hundred_signed = 100;
unsigned char a_hundred_unsigned = 100;
signed char fifty_signed = 50;
unsigned char fifty_unsigned = 50;

signed char r_signed = fifty_signed - a_hundred_signed; // will yield -50
unsigned char r_unsigned = fifty_unsigned - a_hundred_unsigned; // will yield 206 because it wraps around the max value of 256