Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C Programming
Tentative definition versus external linkage
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Jack Klein, post: 3479435"] You are missing the simple fact that the C standard statement is, in 6.9 p5: "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." If you define an external object in more than one translation, you are violating the first "shall" clause in this paragraph. This paragraph is in a "Semantics" section, not a "Constraints" section. Violating a "shall" clause outside of a constraints section means that the program produces undefined behavior, no diagnostic is required. It just so happens that one possible consequence of undefined behavior is for the program to do what you expect and/or want it to do. How the tool set you use deals with a particular case of undefined behavior is up to the tool set, since the C standard imposes no requirements. It just so happens that some tool sets, on some platforms, use a linkage model that allows multiple external definitions, as long as none of them or only one of them, but not more than one, specify an initializer. The linker will merge duplicate external definitions into a single object. It also just so happens that there are a large number of other implementations that will reject this at the link stage, complaining of multiple definitions. Either behavior is allowed by the C standard, as is just about any other, because the behavior is undefined by the standard. -- Jack Klein Home: [URL]http://JK-Technology.Com[/URL] FAQs for comp.lang.c [URL]http://c-faq.com/[/URL] comp.lang.c++ [URL]http://www.parashift.com/c++-faq-lite/[/URL] alt.comp.lang.learn.c-c++ [URL]http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html[/URL] [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C Programming
Tentative definition versus external linkage
Top