Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #145973
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Question about use (and non-use) of "extern" |
| Date | 2019-09-04 12:21 +0200 |
| Organization | A noiseless patient Spider |
| Message-ID | <qko36k$uok$1@dont-email.me> (permalink) |
| References | <qjgric$8u2$1@news.xmission.com> <qk49be$ac$1@dont-email.me> <86tv9ty1t4.fsf@mailhub.linuxsc.com> <qklqqd$u5t$1@dont-email.me> <qkn2tg$6j6$1@dont-email.me> |
On 04/09/2019 03:10, James Kuyper wrote: > On 9/3/19 9:45 AM, David Brown wrote: >> On 03/09/2019 14:57, Tim Rentsch wrote: > ... >>> These statements are misleading. An implementation may legally >>> support this pattern, with no diagnostics, and still conform to >>> the Standard. Nothing in the Standard forbids that. Neither does >>> the Standard require it, but that doesn't make it illegal, just >>> not advisable. (More specifically, the behavior is undefined.) >> >> >> If you have "int x;" in a translation unit (without any "static" >> involved), that counts as an external definition of "x" with external >> linkage. (6.9.2p2 and 6.9.2p1). If this identifier is used in an >> expression (other than an unevaluated expression, such as a sizeof), >> there must be exactly one definition of it (6.9p5). These are "shall" >> rules - they are as strong as the standards get. > > No, the strongest requirements imposed by the standard include a > mandatory diagnostic. A diagnostic is mandatory for violation of a > "shall" or "shall not" statement only when it occurs in a Constraints > section - this one does not. > Thanks for the clarification. > >> I don't see anything in the standards (I'm looking at C11, but I don't >> think these things have changed) requiring a conforming compiler to give >> diagnostics about multiple "int x;" definitions in a program. But as I >> read it, it breaks a "shall" requirement, and that is as close to >> "illegal" as you can get. > > Which isn't very close. A fully conforming implementation of C could > issue all mandatory diagnostics, and then go ahead and complete > translation of the program normally. "Illegal" implies some punishment > if caught, and some effort to catch perpetrators, and that doesn't > apply, not even metaphorically, to any provision of the C standard. > The word "illegal" is used in a wider sense than that in many situations, including software development. The C standard mentions "illegal instructions" - if you execute an "illegal instruction" on a cpu, you can expect a crash, exception, trap, or nasal demons, but not a police officer and a court case. > ... >> But the fact that most C compilers support it, and that a fair amount of >> C code requires it, does not mean the language standard allows it. > > The fact that the C standard does not prohibit a fully conforming > implementation of C from accepting such code, means that the standard > does allow it. It allows a great deal, and prohibits very little. > Fair enough. I was under the impression that "shall" requirements were equally strong, but as you and Keith have now shown me, there is a significant difference between these requirements under "Constraints" and "Semantics". Multiple definitions of an identifier with /internal/ linkage inside a translation unit are a constraint violation, and thus require a diagnostic. Multiple definitions of an identifier with /external/ linking and definitions in different translation units is undefined behaviour - which means compilers can give it a defined behaviour if they want. Thanks for the information and explanation.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Question about use (and non-use) of "extern" gazelle@shell.xmission.com (Kenny McCormack) - 2019-08-20 13:11 +0000
Re: Question about use (and non-use) of "extern" David Brown <david.brown@hesbynett.no> - 2019-08-20 16:09 +0200
Re: Question about use (and non-use) of "extern" Bart <bc@freeuk.com> - 2019-08-20 16:41 +0100
Re: Question about use (and non-use) of "extern" Bart <bc@freeuk.com> - 2019-08-20 16:47 +0100
Re: Question about use (and non-use) of "extern" David Brown <david.brown@hesbynett.no> - 2019-08-20 19:27 +0200
Re: Question about use (and non-use) of "extern" Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2019-08-20 13:54 -0400
Re: Question about use (and non-use) of "extern" Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-08-21 02:09 +0100
Re: Question about use (and non-use) of "extern" David Brown <david.brown@hesbynett.no> - 2019-08-21 10:54 +0200
Re: Question about use (and non-use) of "extern" Bart <bc@freeuk.com> - 2019-08-21 00:41 +0100
Re: Question about use (and non-use) of "extern" David Brown <david.brown@hesbynett.no> - 2019-08-21 10:58 +0200
Re: Question about use (and non-use) of "extern" richard@cogsci.ed.ac.uk (Richard Tobin) - 2019-08-20 16:10 +0000
Re: Question about use (and non-use) of "extern" Siri Cruise <chine.bleu@yahoo.com> - 2019-08-20 16:23 -0700
Re: Question about use (and non-use) of "extern" already5chosen@yahoo.com - 2019-08-21 06:50 -0700
Re: Question about use (and non-use) of "extern" gazelle@shell.xmission.com (Kenny McCormack) - 2019-08-22 20:20 +0000
Re: Question about use (and non-use) of "extern" David Brown <david.brown@hesbynett.no> - 2019-08-23 00:25 +0200
Re: Question about use (and non-use) of "extern" Bart <bc@freeuk.com> - 2019-08-23 01:35 +0100
Re: Question about use (and non-use) of "extern" gazelle@shell.xmission.com (Kenny McCormack) - 2019-08-23 03:40 +0000
Re: Question about use (and non-use) of "extern" Bart <bc@freeuk.com> - 2019-08-23 11:09 +0100
Re: Question about use (and non-use) of "extern" David Brown <david.brown@hesbynett.no> - 2019-08-23 08:16 +0200
Re: Question about use (and non-use) of "extern" scott@slp53.sl.home (Scott Lurndal) - 2019-08-23 15:02 +0000
Re: Question about use (and non-use) of "extern" Bart <bc@freeuk.com> - 2019-08-23 17:06 +0100
Re: Question about use (and non-use) of "extern" gazelle@shell.xmission.com (Kenny McCormack) - 2019-08-23 18:40 +0000
Re: Question about use (and non-use) of "extern" scott@slp53.sl.home (Scott Lurndal) - 2019-08-23 20:38 +0000
Re: Question about use (and non-use) of "extern" Richard Damon <Richard@Damon-Family.org> - 2019-08-23 17:55 -0400
Richard Damon weighs in... (Was: Question about use (and non-use) of "extern") gazelle@shell.xmission.com (Kenny McCormack) - 2019-08-23 23:50 +0000
Re: Question about use (and non-use) of "extern" Andrey Tarasevich <andreytarasevich@hotmail.com> - 2019-08-27 15:03 -0700
Re: Question about use (and non-use) of "extern" Tim Rentsch <tr.17687@z991.linuxsc.com> - 2019-09-03 05:57 -0700
Re: Question about use (and non-use) of "extern" David Brown <david.brown@hesbynett.no> - 2019-09-03 15:45 +0200
Re: Question about use (and non-use) of "extern" Keith Thompson <kst-u@mib.org> - 2019-09-03 11:13 -0700
Re: Question about use (and non-use) of "extern" David Brown <david.brown@hesbynett.no> - 2019-09-04 12:11 +0200
Re: Question about use (and non-use) of "extern" James Kuyper <jameskuyper@alumni.caltech.edu> - 2019-09-04 08:18 -0400
Re: Question about use (and non-use) of "extern" Tim Rentsch <tr.17687@z991.linuxsc.com> - 2019-09-06 02:25 -0700
Re: Question about use (and non-use) of "extern" David Brown <david.brown@hesbynett.no> - 2019-09-06 11:45 +0200
Re: Question about use (and non-use) of "extern" Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-09-06 21:15 +0100
Re: Question about use (and non-use) of "extern" James Kuyper <jameskuyper@alumni.caltech.edu> - 2019-09-03 21:10 -0400
Re: Question about use (and non-use) of "extern" David Brown <david.brown@hesbynett.no> - 2019-09-04 12:21 +0200
Re: Question about use (and non-use) of "extern" Andrey Tarasevich <andreytarasevich@hotmail.com> - 2019-09-04 12:04 -0700
Re: Question about use (and non-use) of "extern" James Kuyper <jameskuyper@alumni.caltech.edu> - 2019-09-04 15:29 -0400
Re: Question about use (and non-use) of "extern" Tim Rentsch <tr.17687@z991.linuxsc.com> - 2019-09-06 02:46 -0700
Re: Question about use (and non-use) of "extern" Bonita Montero <Bonita.Montero@gmail.com> - 2019-09-05 10:01 +0200
Re: Question about use (and non-use) of "extern" Andrey Tarasevich <andreytarasevich@hotmail.com> - 2019-09-05 10:43 -0700
Re: Question about use (and non-use) of "extern" Bonita Montero <Bonita.Montero@gmail.com> - 2019-09-06 20:24 +0200
csiph-web