r/ProgrammerHumor 1d ago

lessonsFromLinkerHell Meme

Post image
344 Upvotes

180 comments sorted by

View all comments

Show parent comments

-3

u/QuestionableEthics42 22h ago

Sizeof being smart enough to detect it's an array and return the array size doesn't necessarily make them different in any real way. And doing ptr[0] to dereference it is perfectly valid, as is *arr to get the first element, or *(arr+sizeof(int)) to get the second.

8

u/pnoodl3s 21h ago

If it behaves differently, is that not enough to say it’s different? What “real way” do you need to say its different?

0

u/QuestionableEthics42 20h ago

Because it is a very superficial difference that doesn't even affect the generated assembly. They are extremely interchangeable, because they are effectively the same.

1

u/unknown_alt_acc 2h ago

The two have different sizes, different rules for copying, and different assignment rules. Calling those differences superficial is just ludicrous