3 ms·
That's assuming it was about saving characters. It's possible the motivation was to save bytes at runtime. On systems whose total RAM is measured in single or d
by adrianmonk 8y ago
That's assuming it was about saving characters. It's possible the motivation was to save bytes at runtime. On systems whose total RAM is measured in single or double digits of kilobytes, that's a strong motivator.
Another possible motivator could be simplifying the compiler implementation by making all arrays work the same way from a code generation point of view. Heap arrays have a size known only at runtime, so it makes sense to carry this size with the array, as the malloc() call does. But stack and global (and static) arrays have a size which is known at compile time, so they do not need a size carried around with them.
Back then, using fixed sized arrays all over the place was common practice. Look at DOS 8.3 character filenames for example. So, dynamic heap allocation might have been viewed as something people wouldn't use constantly. And compilers were a lot simpler, so creating two different implementations for arrays might have seemed excessive.
- pjmlp 8y agoFirst of all, outside Bell Labs there were computers being programmed in high level languages since 1961, definitely much weaker computers than a PDP-11. Secondly, ptr = &array[0] is something would happen at compile time. Third, C authors seem to have a predisposition to ignore state of the art in existing languages.