Liste des Groupes | Revenir à cl c |
On 7/5/2024 3:09 AM, Keith Thompson wrote:[...]BGB <cr88192@gmail.com> writes:
>*1: While not exactly that rare, and can be useful, it is debatable if[...]
they add enough to really justify their complexity and relative
semantic fragility. If using pointers, one almost invariably needs to
fall back to doing "arr[y*N+x]" or similar anyways, so it is arguable
that it could make sense to drop them and have people always do their
multidimensional indexing manually.
>
Note that multidimensional indexing via multiple levels of pointer
indirection would not be effected by this.
Multidimensional arrays in C are not a distinct language feature.
They are simply arrays of arrays, and all operations on them follow
from operations on ordinary arrays and pointers.
Are you proposing (in this hypothetical new language) to add
an arbitrary restriction, so that arrays can have elements of
arithmetic, pointer, struct, etc. type, but not of array type?
I'm not sure I see the point.
As-is, the multidimensional arrays require the compiler to realize
that it needs to multiply one index by the product of all following
indices.
>
So, say:
int a[4][4];
int j, k, l;
l=a[j][k];
>
Essentially needs to be internally translated to, say:
l=a[j*4+k];
>
Eliminating multidimensional arrays eliminates the need for this
translation logic, and the need to be able to represent this case in
the typesystem handling logic (which is, as I see it, in some ways
very different from what one needs for a struct).
I personally would hope that this language would *not* inherit C's>
odd treatment of arrays and pointers. If so, and if it supports
multidimensional arrays, they'd have to be defined differently than
the way they're defined in C.
The idea in this case was to make it so that:
int[16];
Can be functionally identical to:
int*
As far as most of the compiler's type-system handling is concerned. In
this case, one only needs to care about the size when reserving space
for the array.
Les messages affichés proviennent d'usenet.