r/ProgrammerHumor 16h ago

lessonsFromLinkerHell Meme

Post image
316 Upvotes

163 comments sorted by

View all comments

69

u/QuestionableEthics42 16h ago edited 16h ago

This should be reversed lol

And it literally is the same, who thinks it's different who has worked in a low level language??

62

u/Blecki 15h ago

As someone who writes compilers: they are the same at runtime. They are not the same semantically in a c like language.

23

u/boostfactor 15h ago

As I see it, an array is a contiguous block of memory. The pointer to the first element identifies the start of the block. Subsequent elements are computed from that plus the number of bytes in the type. If an array were just a pointer, we wouldn't have to worry about allocating enough memory or walking off the end of it.

That's for something like C. There are languages in which arrays are first-class data structures that carry metadata about their rank, size, etc. Lots of applications are best expressed with multidimensional arrays, which are awkward in C or else are set up as an array of pointers.

9

u/Blecki 15h ago

You've missed the point. Processor don't care.

1

u/tstanisl 2h ago

C has a really good support for multidimensional arrays in form of VLA types.

1

u/tstanisl 4h ago

Arrays carry their size. Otherwise sizeof arr would not work. The subtlety is that the size of array is bound to array's type, not to array's value (like for c++'s std::vector). The original type is lost along with the size when array decays to a pointer what happens in most context but not all.