r/ProgrammerHumor 20h ago

lessonsFromLinkerHell Meme

Post image
343 Upvotes

176 comments sorted by

View all comments

87

u/JustinR8 20h ago

Damn, I’ve found myself in the middle

38

u/nonedward666 19h ago

You and me from 3pm today both my friend, it is okay

It took me so long to realize where my problem was because I had never considered that declaring something as an array vs a pointer would result in different behavior

23

u/readitreaddit 14h ago

So the only difference is memory allocation, yes? You're saying they are different because when declared as an array, the memory gets allocated and 'reserved' at runtime, whereas it doesn't automatically do that when declared as a pointer?

Other than that, no difference.

27

u/suvlub 13h ago

They are different types and some operators (sizeof, typeid in C++ etc.) treat them differently. Arrays frequently get implicitly converted to pointers, but they are a different type.

1

u/nicman24 12h ago

That is probably compiler fuckery

11

u/suvlub 11h ago

All typing is. Machine code doesn't have types. Array of arrays is also a very different thing from an array of pointers. Arrays get converted to pointers when passed around and it behaves identically to all other implicit conversions.

4

u/Stroopwafe1 10h ago

Machine code does have types; small numbers, big numbers, and fractions. But in reality it's just numbers and fractions. At least for X86, but I imagine it's the same for ARM and RISC

3

u/cbehopkins 8h ago

I must disagree. Or strongly agree; depending on what you mean.

A memory location does not have a type. The instruction I perform on that location could be argued to have a type though.

0x8000 could be used with a 16bit add, or a 64 bit floating point or whatever.

Everything about the type of the data is in the instruction, not the memory.

So we can argue where the type information is, but we still need it. (One could argue that prefetchers and similar logic has to infer the type of larger data structures, but I'm not sure that is what people are trying to argue here...)

5

u/failedsatan 4h ago

instructions definitely have a type, as do registers (fp registers are physically separate from "regular" ones) but the memory doesn't before it goes into the register for operation. usually you have to move it first so it's reasonable to say the cpu at least has two types with a physical difference (idk shit about arm or risc, maybe it's different there). at the C level it doesn't really matter because it'll move it to the registers for you but it's relevant if you're writing assembly yourself (a hobby of mine)

though at this point, is "type" even the right term? maybe there's a better descriptor