On Fri 7/25/2025 10:43 PM, Lawrence D'Oliveiro wrote:
The articles on the development of C include some interesting
historical detail. One point that stood out for me was the handling of
global variables.
When I first came across C (back in K&R days), the semantics of
duplicated global variable declarations -- overlay the allocated
storage for each allocation of a variable with the same name, so the
variable ends up being the largest size of all the declarations --
immediately reminded me of Fortran COMMON blocks. And one article
makes it clear that was a conscious decision, to try to ease
implementation of the language on non-Unix systems.
Both C89/90 rationale and C99 rationale have entire sections on the
ref/def models, which were taken into consideration. They provides the
same reasoning for the decision made by the committee: not burdening the weaker platforms with the task of merging/cleaning-out repetitive definitions. The responsibility to ensure that there is at most one definition for entities with external linkage lies on the user.
On a related note, it is interesting to point out that the language continues to staunchly stick to the same approach in its later
iterations: C99 introduced inline functions, and the definition model
for inline functions with external linkage is also strikingly different from, say, C++. The user is required to manually choose the definition
site and provide only one `extern inline` definition for the function
(i.e. regular non-inlined body, in case the compiler decides to use one).
Sysop: | DaiTengu |
---|---|
Location: | Appleton, WI |
Users: | 1,073 |
Nodes: | 10 (0 / 10) |
Uptime: | 222:34:49 |
Calls: | 13,783 |
Calls today: | 1 |
Files: | 186,987 |
D/L today: |
702 files (242M bytes) |
Messages: | 2,434,871 |