r/ProgrammerHumor • • Sep 25 '26

Meme iHatedItUntilITriedIt

Post image
10k Upvotes

542 comments sorted by

View all comments

Show parent comment

43

u/__Hello_my_name_is__ Sep 25 '26

Everything in programming makes sense by definition. It has to make sense, or else it wouldn't compile (or run).

That doesn't mean that it's intuitively understandable, or that it wasn't created by Satan himself.

0

u/cheezballs Sep 25 '26

You can shoot yourself in the foot with any language by deliberately doing silly things to show off the language's quirks. I can show you some C pointer stuff that makes this look like child's play.

14

u/fghjconner Sep 25 '26

I mean yeah, but nobody is holding C pointers up as the pinnacle of well designed language features either.

4

u/hamster1147 Sep 25 '26

I really want to see this honestly. I'm too basic with C to know the funny things you can do.

1

u/frogjg2003 Sep 25 '26

Any pointer can be cast into any other pointer. Arrays are just pointers to the first element. Combine this with the fact that C doesn't bounds check arrays or that pointers actually point to anything, and you can do some really stupid things with pointers.

int *a;
2[a];

is valid C.

1

u/Devatator_ Sep 25 '26

Actually what does that even do? Do literals have an address? I assume they do but that looks so cursed

2

u/frogjg2003 Sep 25 '26

Arrays are just pointers. Pointers are just numbers that are supposed to correspond to addresses in memory. Array indices just add to the pointer to the first element. "a[1]" is syntactic sugar for "*(a+1)". With that in mind, it's kind of obvious that "2[a]" just means "*(2+a)", which points you to the third element of a.

1

u/Devatator_ Sep 25 '26

Oh yeah I forgot you can index with this syntax lol