Liste des Groupes | Revenir à cl c |
On 07/04/2025 20:31, bart wrote:C simply has the requirement for separate compilation of modules. Where does it specify how the implementation does that?On 07/04/2025 19:02, Michael S wrote:On Mon, 07 Apr 2025 05:45:19 -0700No.Of course, proposals for similar feature in other procedural/imperative>
language would not be totally different. Pascal is more similar to C
than many other procedural languages, so solution for Pascal would
likely be more similar to C than for example, stackless co-routines
that already exist in such languages like C# (that started current wave
of popularity of the feature) or Python.
However Pascal and C have enough not in common for significant
difference in proposed syntax and implementation. Specifically, in
Pascal:
- heap management is built-n in the language
- non-local goto is built-n in the language
That's news to me. But then I only used an educational version.
>- nested procedures>
- everything related to separated compilation of the translation units
is handwaved in the docs rather than strictly specified.
I don't think it's that strictly specified in C. Isn't it vaguely left to the implementation?
>
From the programmer point of view, they are shared. But the language provides no specific mechanism for that.Much of how different units share macros, types, structs and enums isn't part of the language at all AFAICS: it's just a by-product of different modules happening to include the same header files.Linkage is explained in 6.2.2 - only identifiers with external linkage are shared amongst translation units. Macros, types, enums are all have no linkage and are therefore never shared.
>
The only way to make new non-standard types in C is with "struct", "union" or "enum". Section 6.2.7 of the standard sets out simply and clearly what is required for two types in different translation units to be compatible. (It doesn't make sense to say they are the "same type" in C lingo, since types have no linkage, but compatibility is the important point.)The programmer can achieve the objective in multiple ways; that's what's ad hoc. The implementation itself works by crossing its fingers and hoping that the multiple declarations of the common entity X that are seen by the different translation unit are fully compatible.
Sharing a definition in a header file is normally the easiest way to ensure that the types used in different translation files are compatible, but it is not required.
But it could also be done by repeating declarations in each module; it's rather ad hoc.It is not remotely "ad hoc" - as far as the language is concerned, including a header file /is/ repeating the declaration in the different translation units.
The way C handles this kind of thing is arguably weaker than in languages that have proper modules (like Ada, or Modula 2), and much more open to mistakes. On the other hand, it is very flexible and simple to understand,The preprocessor mechanisms available to work with source code are fairly easy to grasp (but may be complex in practice with multiple nested headers spread over a file system).
specialised object files or "interface" files. It is possible to write C code in an "ad hoc" manner (such as declaring an "extern" identifier within a C file rather than a header file), but the language definition is not "ad hoc".So, what are the rules again for mixing 'extern' and 'static' declarations? Since this passes gcc:
Les messages affichés proviennent d'usenet.