Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Global variables Date: Mon, 07 May 2018 08:49:02 -0700 Organization: None to speak of Lines: 40 Message-ID: References: <87o9hsqk7d.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="9b5f9547cb5f5c2e6ac0a9ad03204119"; logging-data="30491"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/uSgz/o1dsC7qn6nBp9w/3" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:hdkJMuFZXmWOe1nLlbFkrYqqM+w= sha1:lLUIwGSB+ZF/nvSNNlaksfHl6iA= Xref: csiph.com comp.lang.c:130320 David Brown writes: > On 07/05/18 04:21, Ben Bacarisse wrote: >> Richard Damon writes: >>> On 5/6/18 5:57 PM, David Brown wrote: > >>> >>> Yes, the normative description is implicitly of a single definition, so >>> the lack of any other mention makes it fall as undefined by omission. >> >> I'm not seeing this, though I may have lost track of this discussion! >> The behaviour appears to be explicitly undefined due to the violation of >> a "shall": >> >> 6.9 >> ... >> 5 [...] If an identifier declared with external linkage is used in an >> expression [...], somewhere in the entire program there shall be >> exactly one external definition for the identifier; otherwise, there >> shall be no more than one." >> > > It seems 6.9p5 is the bit I have been missing, and that it does say > explicitly that you may not have more than one definition of the same > object (or function) in the program. So despite being commonly > supported by most C implementations (unless you use something like > "-fno-common"), having multiple "int x;" definitions in different > compilation units in the same program is not allowed. > > Thanks to Richard and Ben (and others) for educating me here. It's not exactly "not allowed". Having multiple definitions violates a "shall" outside a constraint, so it causes undefined behavior. An implementation is free to define the behavior in any way it likes, or to behave in any way it likes without documenting the behavior. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"