Liste des Groupes | Revenir à cl c |
On 11/07/2024 09:54, Michael S wrote:
No.No, it isn't.
If [in C] it was possible to pass arrays to functions, either by value
or by reference, then callee would know the length of passed array. As
it is, callee does not know it.The length can be passed in a separate parameter, but then it does notThat's rather specious. In my language (probably in C too), most passed arrays are unbounded, allowing the same function to work with arrays of different sizes.
have to be the same as an original.
So that would need a separate Length parameter, even using by-reference.
In that regard, it's no different from the C: my array by-ref and C's alledged by-ref both cannot determine the array length solely from the parameter.No, it cannot access the bounds of the "array parameter" here. (I use quotation marks because there are no array parameters in C - just things that look a little like them.)
(In my language, attempts to get the length yields 0, which makes sense as the parameter's bounds are zero. In C, it will yield the size of the pointer.)
But when the array IS bounded, then in C:
typedef byte vector[4];
void F(vector a) {
printf("%zu\n", sizeof(a));
printf("%zu\n", sizeof(vector));
}
The first printf shows 8 (the pointer size); the second shows 4 (the array size). So it /can/ access the bounds.
(For unbounded arrays, my language offers an alternative: slices, which contain their length. This is available whatever the calling mechanism.)A slice is presumably an object that encapsulates a pointer to data and size information - a struct. It might give a nice syntax in your language, but it is a different concept entirely.
Les messages affichés proviennent d'usenet.