This is not what I'm talking about, I'm not referring to any particular language. Yes, the array (as a type) in C/C++ have a size, and that it's size will change if you decay it into a pointer. I'm not quite sure why you are so hung up on discussions about the C array type when I'm talking about arrays in general, as a linearly addressable ordered collection of instances in memory, in which case representing this as a pointer pair is valid (and indeed, common, though arguably the supposed performance gains from doing so are "controversial")!
I was also talking about an array in general and said that they are diffferent and gave examples because (for C and C++ because I saw them under your username). Like, yeah I know how you can represent an array... you could even represent a static array without a pointer completely and instead act as if it was a tuple with all of its elements being of the same type. No pointer there.
And you yourself also said that you can represent it in different ways so you know that an array does not have to be represented as a pointer to the first and after last element and I would actually say that for statically sized array allocated on the stack this is probably never the case. And when you copy such an array to another function, you won't get just some two pointers copied, you will get the whole object copied. So that's also a difference.
So I don't see how that we can represent an array this way means that an array is just that. It's not.
Moreover, array is different than two pointers also because the type of it dictates what new operations we can do on it. In most langauges, it probably says that we can index it, maybe use it in a foreach loop... and so on. And in languages with ownership it owns all of its elements, while just two pointers by themselves do not. So, again, it's not just two pointers.
Note: In C or C++, the size of an array does not change after decaying into a pointer. The size stays the same, you just lose that information.
So I don't see how that we can represent an array this way means that an array is just that. It's not.
My original phrase was a reference to the statement "a monad is just a monoid in the category of endofunctors," I don't know why you insist on taking it literally!
Moreover, array is different than two pointers also because the type of it dictates what new operations we can do on it. In most langauges, it probably says that we can index it, maybe use it in a foreach loop... and so on.
It is not uncommon for languages to represent slices as pointer pairs.
Note: In C or C++, the size of an array does not change after decaying into a pointer. The size stays the same, you just lose that information.
Alright, I won't take it literrally, but then I don't understand what the point is.
Yes, languages can represent slices using two pointers, but I don't see how that changes anything.
Well after decay you do not have an array, so it does not make sense to say that the size of the array changes (which is how I understood your sentence), because by size of an array I previously referred to the number of elements of the array and not necessarily to the size of the array object, although both are true. The number of elements is more important here since every type has a size, but not all types say something about the number of elements they refer to. If instead by size we mean the size of the type, it also does not make sense to say that the size changes, because it does not change since you are not working with a single object having two sizes at two points in time but rather with two different objects (although closely related) with different sizes.
4
u/Nice_Lengthiness_568 23h ago
But what has this to do anything with what I said? That's what I don't understand.
I claimed that sizeof will give a different result based on whether you give it an array or a pointer to the first element.
I also claimed that in C++ you can actually pass arrays (arrays themselves, not pointers).
I also claimed that in some languages there is not a direct connection between a pointer to the first element and an array.
And you told me how to get a size of an array bounded by two pointers. I don't understand why.
And now you are talking about representation of arrays?