3 ms·
> Because you can't do that and still call the resulting language C You could if you introduced a new type of "safe array". e.g. int[] is a traditional C arr
by skissane 2y ago
> Because you can't do that and still call the resulting language C
You could if you introduced a new type of "safe array".
e.g.
int[] is a traditional C array which decays to int*
int[@] is a "safe C array" which is syntactic sugar for struct { size_t __count; int* __items; }, and as such can't decay
int[] and int[@] would not be directly interoperable, except by converting both to int* – maybe casting an int[@] to int* would automatically extract the __items member.
(The [@] syntax was chosen at random, if you don't like it, pick something else.)
- pif 2y agoYou can define such a struct yourself. You do not need to modify the language.
- SpaghettiCthulu 2y agoBut your struct cannot provide an indexing operator (right?)
- adrianN 2y agoBy having it defined at the language level you increase the chances that your dependencies use the same struct.
- orf 2y agoSo why do we have so many issues with arrays then, since everyone can individually fix it themselves? Hmm…