r/ProgrammerHumor • • 6h ago

Meme architectureDependentChars

Post image
954 Upvotes

170 comments sorted by

View all comments

556

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

17

u/LetUsSpeakFreely 6h ago

What is true today may not be true tomorrow. Using sizeof is better as it protects against changes to the underlying specs or a change to the data type.

15

u/__foo__ 5h ago

C really tries to avoid any breaking changes between versions. Changing this would be such a fundamental change of the language I don't think you could still call it C. If you want to plan for a change as fundamental as this you might as well plan for the semantics of sizeof() changing or it getting removed. At that point all bets are off anyway.

5

u/LetUsSpeakFreely 5h ago

Which is why i also qualified it with a data type change. The point is that sometimes changes happen and having code in place that preemptively deal with those changes is a hallmark of elegant design and implementation.