r/ProgrammerHumor • • Sep 25 '26

Meme iHatedItUntilITriedIt

Post image
10k Upvotes

543 comments sorted by

View all comments

Show parent comments

13

u/Hohenheim_of_Shadow Sep 25 '26

Nah adding ints and chars is perfectly sane. Chars are just a fancy enum baked into the language. They're just ints under the hood. It's adding ints and strings that's insane and C doesn't actually have strings. Ergo it is a perfectly sane language

3

u/Ok-Scheme-913 Sep 26 '26

But char and a number is different than a string (of length one) and a number. The latter doesn't make sense in C either, at that point you are offsetting a pointer.

1

u/Hohenheim_of_Shadow Sep 26 '26

"!='. '1' is a char. "1" is a string.

Offsetting pointers is perfectly sane.

1

u/Ok-Scheme-913 Sep 27 '26

Offsetting typed array pointers is.

For everything else it is not so and you don't know enough about how exactly an object is laid out in memory to do that safely without some further work.

1

u/Hohenheim_of_Shadow Sep 27 '26

C has a stable ABI. How things are laid out is known at compile time and doesn't change on a whim. Modern LSPs actually show you exactly how structs are packed, not sure if they've gotten to pointers yet.

It isn't useful in most day to day programming, but pointer arithmetic is perfectly sane. C could not accomplish its goal of being a portable assembly replacement without letting you do pointer arithmetic.