3 ms·
The problem with arrays is not that they decay to pointers, its that they arent pointers to begin with. This: int x[10]; Sould mean "put 10 ints in memory, an
by quelsolaar 4y ago
The problem with arrays is not that they decay to pointers, its that they arent pointers to begin with. This:
int x[10];
Sould mean "put 10 ints in memory, and make x the pointer to it.". The thing that messes this up is sizeof. sizeof(x) doesnt give the size of the pointer like it should, it gives you the size of the array. If that was fixed (obviusly it can without breaking everything) then things would be much better and consistent.
- WastingMyTime89 4y agoYes, sizeof has a primitive as a weird behaviour when used in the scope of a continuous allocation. I agree it’s unfortunate. But "arrays" definitely are pointers. I put "arrays" in quote because C has nothing I would personally call an array. It’s just contiguous memory allocation. It’s to the point that 10[a] and a[10] are desugared to the same thing.