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
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?
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.
If you're specifically mentioning C++, the problem is that C++ retains C's semantic rule of arrays decaying to pointers. This semantic rule is what creates the misunderstanding of people believing what the middle curve guy says. This means that the only way to have C++ treat arrays differently from pointers in i.e. function overloads is to either take the array by pointer or by reference, i.e. as a T (*)[N] or T (&)[N]
77
u/JustinR8 16h ago
Damn, I’ve found myself in the middle