7 ms·
This is incorrect, but most C and C++ programmers would be stumped by `int(*y)[3]` (which is how you spell a pointer to an array of length 3).
by david2ndaccount 4y ago
This is incorrect, but most C and C++ programmers would be stumped by `int(*y)[3]` (which is how you spell a pointer to an array of length 3).
- pjmlp 4y agoPlenty of C++ developers still mix up delete versus delete[].
- olliej 4y agoWhich is my point: the type system doesn't distinguish T* (a single object) T* (an array of objects), so delete vs delete[] only shows up as runtime heap corruption that may or may not eagerly terminate or lead to RCE.
- olliej 4y agoThe type of `new T[N]` is T. The type of `new T[10]` is also T. The type of `new T` is also T. Yes if you have a statically sized array you can make a pointer to an array of that length, but those are generally not relevant outside of specific cases (arrays in structs or on the stack where the size impacts offsets in codegen). More over the desire of C and C++ to drop those annotations is such that even using your proposal of a pointer to an array rather than just an array, is of questionable value. Take an extension of your example: int(*y)[3] = ...; int(*y2)[3] = ...; You can't do *y2 = *y; Because C doesn't let you assign arrays by value, even fixed size ones \o/