Re: Help wanted on some source codes



Jack Klein wrote:
> On 29 Nov 2005 18:34:15 -0800, "slebetman@xxxxxxxxx"
> <slebetman@xxxxxxxxx> wrote in comp.lang.c:
> > The programs are rubbish of course. But wouldn't the file scope of x
> > mean that function f() is actually refering to the double x instead of
> > the int x?
>
> This is part of what I posted in a reply to the OP, but I'll repeat it
> here for your benefit. The issue here is NOT file scope, but most
> specifically IS external linkage:
>
> The C standard says this in "6.9 External definitions" paragraph 5:
>
> "An external definition is an external declaration that is also a
> definition of a function (other than an inline definition) or an
> object. If an identifier declared with external linkage is used in an
> expression (other than as part of the operand of a sizeof operator
> whose result is an integer constant), somewhere in the entire program
> there shall be exactly one external definition for the identifier;
> otherwise, there shall be no more than one."
>
> Violating a 'shall' outside of a constraint section is just plain old
> ordinary undefined behavior. You have left planet C behind and
> entered the Twilight Zone, and there is no right or wrong.
>

Yes I understand that. But I didn't think all globals are external
linkage by default. I thought you need to use the 'extern' keyword for
that. So, without extern globals with the same name have undefined
behavior? I'm guessing that globals declared with the 'static' keyword
can have the same name.

.



Relevant Pages

  • Re: extern variable
    ... If extern in missing in second and third file, ... is available to all translation units in the program. ... exactly one external definition for the identifier; ...
    (comp.lang.c)
  • Re: "extern" question?
    ... don't use "extern", it works. ... object (a declaration without the extern keyword, ... extern int x; ... must be exactly one and only one external definition. ...
    (comp.lang.c)
  • Re: Using only "extern" declarations
    ... program be declared in each one with the "extern" storage-class specifier, ... "An external definition is an external declaration that is also a ... there shall be exactly one external definition for the identifier; ... contain an external definition with an initializer of 0. ...
    (comp.lang.c.moderated)
  • Re: globals (again?)
    ... one in the relevent module, but it rather defeats the whole purpose. ... variable `extern' in those other files. ... so far as to say "Never use globals," which I think overstates ... extern struct globals my_globals; ...
    (comp.lang.c)
  • Re: globals (again?)
    ... I know I can do an extern on each one in the relevent module, but it rather defeats the whole purpose. ... so far as to say "Never use globals," which I think overstates ... extern struct globals my_globals; ...
    (comp.lang.c)