Hacker News new | past | comments | ask | show | jobs | submit login

> 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.)




You can define such a struct yourself. You do not need to modify the language.


By having it defined at the language level you increase the chances that your dependencies use the same struct.


But your struct cannot provide an indexing operator (right?)


So why do we have so many issues with arrays then, since everyone can individually fix it themselves? Hmm…




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: