• Re: Early History Of C

    From Jakob Bohm@egenagwemdimtapsar@jbohm.dk to alt.folklore.computers,comp.lang.c on Sun Aug 17 20:41:18 2025
    From Newsgroup: alt.folklore.computers

    On 2025-07-27 02:11, Andrey Tarasevich wrote:
    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).


    In stark contrast to this approach, some major compilers require a
    linker with support for many global common blocks, and use this for
    features such as merging identical string literals across compilation
    units, such that 1000 compilation units each having logic to print the
    string "Error", will only consume a single 6 bytes of linked program
    size . This is of cause because those compilers enjoy the luxury of
    requiring specific linker implementations .

    As for global vars, I maintain an internal library that has relies on a compiler-initialized opaque global being initialized using the internal implementation types, while most users will see only a same size opaque
    type (appropriate static asserts check the size identity).


    Enjoy

    Jakob
    --
    Jakob Bohm, MSc.Eng., I speak only for myself, not my company
    This public discussion message is non-binding and may contain errors
    All trademarks and other things belong to their owners, if any.
    --- Synchronet 3.21a-Linux NewsLink 1.2