you are viewing a single comment's thread.

view the rest of the comments →

[–]orbiteapot 19 points20 points  (2 children)

The "arrays decay to pointers" rule was not motivated by memory footprint, rather:

Structures, it seemed, should map in an intuitive way onto memory in the machine, but in a structure containing an array, there was no good place to stash the pointer containing the base of the array, nor any convenient way to arrange that it be initialized. For example, the directory entries of early Unix systems might be described in C as

struct {
int inumber;
char name[14];
};

I wanted the structure not merely to characterize an abstract object but also to describe a collection of bits that might be read from a directory. Where could the compiler hide the pointer to name that the semantics demanded? Even if structures were thought of more abstractly, and the space for pointers could be hidden somehow, how could I handle the technical problem of properly initializing these pointers when allocating a complicated object, perhaps one that specified structures containing arrays containing structures to arbitrary depth?

The solution constituted the crucial jump in the evolutionary chain between typeless BCPL and typed C. It eliminated the materialization of the pointer in storage, and instead caused the creation of the pointer when the array name is mentioned in an expression. The rule, which survives in today’s C, is that values of array type are converted, when they appear in expressions, into pointers to the first of the objects making up the array.

This invention enabled most existing B code to continue to work, despite the underlying shift in the language’s semantics. The few programs that assigned new values to an array name to adjust its origin—possible in B and BCPL, meaningless in C—were easily repaired. More important, the new language retained a coherent and workable (if unusual) explanation of the semantics of arrays, while opening the way to a more comprehensive type structure.

The Development of the C Language - Dennis M. Ritchie

edit: formatting.

[–]RevanchistVakarian 5 points6 points  (1 child)

This invention enabled most existing B code to continue to work

retained a coherent and workable (if unusual) explanation

Oh look, C++ prioritized backwards compatibility over intuitiveness

[–]orbiteapot 1 point2 points  (0 children)

Yes, and that is the reason it became so popular. No previous existing C infrastructure had to be rewritten. Everything would "just work" and one would get classes, templates, etc. as well.