Liste des Groupes | Revenir à cl c |
On 10/04/2025 20:05, David Brown wrote:It would be much simpler if we had "static int x;" to mean "declare x>
with internal linkage and define it", "extern int x;" to mean "declare x
to have extern linkage", and "int x;" to mean "declare x with external
linkage and define it". That is how you use these in most circumstances
(and there are gcc warning flags to enforce it, for those that want to
do that).
It can't be that simple in C because of shared headers.
>
If module A wants to export 'abc' to other modules, then the source code
seen by the compiler for A.c has to look like this:
>
extern int abc; // in A.h
......
int abc; // in A.c
>
>
The other modules include A.h and see 'extern int abc' which means 'abc'
is imported. But its home module sees both of these, including the
'extern' version, but here 'abc' is exported!
>
That is counter-intuitive: how can a module both import a name (via
'extern int') and export it (via 'int' without 'static')?
Les messages affichés proviennent d'usenet.