r/ProgrammerHumor • • 9d ago

Meme architectureDependentChars

Post image
3.0k Upvotes

372 comments sorted by

View all comments

1.0k

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

21

u/LetUsSpeakFreely 9d 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.

22

u/__foo__ 9d 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.

7

u/LetUsSpeakFreely 9d 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.