Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #103611 > unrolled thread
| Started by | BartC <bc@freeuk.com> |
|---|---|
| First post | 2017-02-10 17:16 +0000 |
| Last post | 2017-02-11 03:17 -0800 |
| Articles | 5 on this page of 105 — 19 participants |
Back to article view | Back to comp.lang.c
Is 'extern' necessary? BartC <bc@freeuk.com> - 2017-02-10 17:16 +0000
Re: Is 'extern' necessary? Keith Thompson <kst-u@mib.org> - 2017-02-10 09:33 -0800
Re: Is 'extern' necessary? BartC <bc@freeuk.com> - 2017-02-10 18:41 +0000
Re: Is 'extern' necessary? Keith Thompson <kst-u@mib.org> - 2017-02-10 12:09 -0800
Re: Is 'extern' necessary? BartC <bc@freeuk.com> - 2017-02-10 20:29 +0000
Re: Is 'extern' necessary? Keith Thompson <kst-u@mib.org> - 2017-02-10 13:26 -0800
Re: Is 'extern' necessary? BartC <bc@freeuk.com> - 2017-02-10 22:56 +0000
Re: Is 'extern' necessary? jameskuyper@verizon.net - 2017-02-10 20:19 -0800
Re: Is 'extern' necessary? "James R. Kuyper" <jameskuyper@verizon.net> - 2017-02-11 09:53 -0500
Re: Is 'extern' necessary? Tim Rentsch <txr@alumni.caltech.edu> - 2017-02-13 05:19 -0800
Re: Is 'extern' necessary? jameskuyper@verizon.net - 2017-02-10 12:09 -0800
Re: Is 'extern' necessary? BartC <bc@freeuk.com> - 2017-02-10 20:50 +0000
Re: Is 'extern' necessary? supercat@casperkitty.com - 2017-02-10 13:09 -0800
Re: Is 'extern' necessary? Keith Thompson <kst-u@mib.org> - 2017-02-10 13:33 -0800
Re: Is 'extern' necessary? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-02-10 23:23 +0000
Re: Is 'extern' necessary? BartC <bc@freeuk.com> - 2017-02-10 23:35 +0000
Re: Is 'extern' necessary? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-02-11 00:34 +0000
Re: Is 'extern' necessary? David Brown <david.brown@hesbynett.no> - 2017-02-13 12:41 +0100
Re: Is 'extern' necessary? BartC <bc@freeuk.com> - 2017-02-13 13:14 +0000
Re: Is 'extern' necessary? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-02-13 14:05 +0000
Re: Is 'extern' necessary? jameskuyper@verizon.net - 2017-02-13 07:49 -0800
Re: Is 'extern' necessary? jameskuyper@verizon.net - 2017-02-10 19:33 -0800
Re: Is 'extern' necessary? supercat@casperkitty.com - 2017-02-11 09:41 -0800
Re: Is 'extern' necessary? Keith Thompson <kst-u@mib.org> - 2017-02-11 10:19 -0800
Re: Is 'extern' necessary? "James R. Kuyper" <jameskuyper@verizon.net> - 2017-02-11 13:39 -0500
Re: Is 'extern' necessary? supercat@casperkitty.com - 2017-02-12 10:10 -0800
Re: Is 'extern' necessary? Andrey Tarasevich <andreytarasevich@hotmail.com> - 2017-02-10 14:59 -0800
Re: Is 'extern' necessary? David Brown <david.brown@hesbynett.no> - 2017-02-13 12:33 +0100
Re: Is 'extern' necessary? Siri Cruise <chine.bleu@yahoo.com> - 2017-02-10 09:35 -0800
Re: Is 'extern' necessary? Keith Thompson <kst-u@mib.org> - 2017-02-10 12:12 -0800
Re: Is 'extern' necessary? jameskuyper@verizon.net - 2017-02-10 10:38 -0800
Re: Is 'extern' necessary? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-02-10 21:10 +0000
Re: Is 'extern' necessary? supercat@casperkitty.com - 2017-02-10 13:25 -0800
Re: Is 'extern' necessary? Andrey Tarasevich <andreytarasevich@hotmail.com> - 2017-02-10 14:53 -0800
Re: Is 'extern' necessary? Andrey Tarasevich <andreytarasevich@hotmail.com> - 2017-02-10 15:06 -0800
Re: Is 'extern' necessary? BartC <bc@freeuk.com> - 2017-02-10 23:24 +0000
Re: Is 'extern' necessary? Ian Collins <ian-news@hotmail.com> - 2017-02-11 12:34 +1300
Re: Is 'extern' necessary? David Brown <david.brown@hesbynett.no> - 2017-02-13 13:14 +0100
Re: Is 'extern' necessary? GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-02-13 13:44 +0100
Re: Is 'extern' necessary? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-02-13 14:13 +0000
Re: Is 'extern' necessary? David Brown <david.brown@hesbynett.no> - 2017-02-13 15:16 +0100
Re: Is 'extern' necessary? GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-02-13 17:24 +0100
Re: Is 'extern' necessary? "James R. Kuyper" <jameskuyper@verizon.net> - 2017-02-13 14:24 -0500
Re: Is 'extern' necessary? David Brown <david.brown@hesbynett.no> - 2017-02-13 23:29 +0100
Re: Is 'extern' necessary? Keith Thompson <kst-u@mib.org> - 2017-02-13 11:06 -0800
Re: Is 'extern' necessary? Andrey Tarasevich <andreytarasevich@hotmail.com> - 2017-02-13 11:15 -0800
Re: Is 'extern' necessary? "James R. Kuyper" <jameskuyper@verizon.net> - 2017-02-13 11:48 -0500
Re: Is 'extern' necessary? supercat@casperkitty.com - 2017-02-13 09:03 -0800
Re: Is 'extern' necessary? David Brown <david.brown@hesbynett.no> - 2017-02-13 23:37 +0100
Re: Is 'extern' necessary? Andrey Tarasevich <andreytarasevich@hotmail.com> - 2017-02-10 15:40 -0800
Re: Is 'extern' necessary? Tim Rentsch <txr@alumni.caltech.edu> - 2017-02-13 05:09 -0800
Re: Is 'extern' necessary? BartC <bc@freeuk.com> - 2017-02-13 13:46 +0000
Re: Is 'extern' necessary? Keith Thompson <kst-u@mib.org> - 2017-02-13 09:52 -0800
Re: Is 'extern' necessary? BartC <bc@freeuk.com> - 2017-02-13 19:19 +0000
Re: Is 'extern' necessary? Keith Thompson <kst-u@mib.org> - 2017-02-13 11:34 -0800
Re: Is 'extern' necessary? BartC <bc@freeuk.com> - 2017-02-13 20:13 +0000
Re: Is 'extern' necessary? Andrey Tarasevich <andreytarasevich@hotmail.com> - 2017-02-13 13:11 -0800
Re: Is 'extern' necessary? David Brown <david.brown@hesbynett.no> - 2017-02-14 00:33 +0100
Re: Is 'extern' necessary? BartC <bc@freeuk.com> - 2017-02-14 01:02 +0000
Re: Is 'extern' necessary? David Brown <david.brown@hesbynett.no> - 2017-02-14 09:28 +0100
Re: Is 'extern' necessary? Robert Wessel <robertwessel2@yahoo.com> - 2017-02-14 03:31 -0600
Re: Is 'extern' necessary? BartC <bc@freeuk.com> - 2017-02-14 11:42 +0000
Re: Is 'extern' necessary? David Brown <david.brown@hesbynett.no> - 2017-02-14 13:29 +0100
Re: Is 'extern' necessary? supercat@casperkitty.com - 2017-02-14 05:16 -0800
Re: Is 'extern' necessary? David Brown <david.brown@hesbynett.no> - 2017-02-14 14:51 +0100
Re: Is 'extern' necessary? supercat@casperkitty.com - 2017-02-14 07:24 -0800
Re: Is 'extern' necessary? David Brown <david.brown@hesbynett.no> - 2017-02-14 21:35 +0100
Re: Is 'extern' necessary? James Kuyper <jameskuyper@verizon.net> - 2017-02-14 15:53 -0500
Re: Is 'extern' necessary? David Brown <david.brown@hesbynett.no> - 2017-02-15 09:31 +0100
Re: Is 'extern' necessary? "James R. Kuyper" <jameskuyper@verizon.net> - 2017-02-15 11:36 -0500
Re: Is 'extern' necessary? Keith Thompson <kst-u@mib.org> - 2017-02-15 09:12 -0800
Re: Is 'extern' necessary? "James R. Kuyper" <jameskuyper@verizon.net> - 2017-02-15 12:58 -0500
Re: Is 'extern' necessary? supercat@casperkitty.com - 2017-02-15 10:01 -0800
Re: Is 'extern' necessary? jameskuyper@verizon.net - 2017-02-15 10:55 -0800
Re: Is 'extern' necessary? supercat@casperkitty.com - 2017-02-15 11:42 -0800
Re: Is 'extern' necessary? jameskuyper@verizon.net - 2017-02-15 12:28 -0800
Re: Is 'extern' necessary? supercat@casperkitty.com - 2017-02-15 13:58 -0800
Re: Is 'extern' necessary? Keith Thompson <kst-u@mib.org> - 2017-02-14 08:54 -0800
Re: Is 'extern' necessary? Keith Thompson <kst-u@mib.org> - 2017-02-14 08:51 -0800
Re: Is 'extern' necessary? Richard Heathfield <rjh@cpax.org.uk> - 2017-02-14 17:32 +0000
Re: Is 'extern' necessary? Gareth Owen <gwowen@gmail.com> - 2017-02-14 17:45 +0000
Re: Is 'extern' necessary? David Brown <david.brown@hesbynett.no> - 2017-02-14 21:38 +0100
Re: Is 'extern' necessary? BartC <bc@freeuk.com> - 2017-02-14 23:26 +0000
Re: Is 'extern' necessary? Keith Thompson <kst-u@mib.org> - 2017-02-14 16:33 -0800
Re: Is 'extern' necessary? BartC <bc@freeuk.com> - 2017-02-15 00:47 +0000
Re: Is 'extern' necessary? Jean-Marc Bourguet <jm@bourguet.org> - 2017-02-14 18:17 +0100
Re: Is 'extern' necessary? Keith Thompson <kst-u@mib.org> - 2017-02-14 09:47 -0800
Re: Is 'extern' necessary? BartC <bc@freeuk.com> - 2017-02-14 18:36 +0000
Re: Is 'extern' necessary? jameskuyper@verizon.net - 2017-02-14 11:20 -0800
Re: Is 'extern' necessary? supercat@casperkitty.com - 2017-02-14 11:42 -0800
Re: Is 'extern' necessary? BartC <bc@freeuk.com> - 2017-02-14 20:22 +0000
Re: Is 'extern' necessary? Robert Wessel <robertwessel2@yahoo.com> - 2017-02-14 17:58 -0600
Re: Is 'extern' necessary? BartC <bc@freeuk.com> - 2017-02-15 01:29 +0000
Re: Is 'extern' necessary? Robert Wessel <robertwessel2@yahoo.com> - 2017-02-16 05:02 -0600
Re: Is 'extern' necessary? BartC <bc@freeuk.com> - 2017-02-16 11:38 +0000
Re: Is 'extern' necessary? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-02-16 14:37 +0000
Re: Is 'extern' necessary? BartC <bc@freeuk.com> - 2017-02-16 15:43 +0000
Re: Is 'extern' necessary? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-02-16 16:08 +0000
Re: Is 'extern' necessary? GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-02-16 18:42 +0100
Re: Is 'extern' necessary? David Brown <david.brown@hesbynett.no> - 2017-02-15 09:47 +0100
Re: Is 'extern' necessary? Robert Wessel <robertwessel2@yahoo.com> - 2017-02-16 05:05 -0600
Re: Is 'extern' necessary? Tim Rentsch <txr@alumni.caltech.edu> - 2017-02-15 16:53 -0800
Re: Is 'extern' necessary? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-02-10 23:55 +0000
Re: Is 'extern' necessary? Les Cargill <lcargill99@comcast.com> - 2017-02-10 19:24 -0600
Re: Is 'extern' necessary? void <nathan.gothier@gmail.com> - 2017-02-11 03:17 -0800
Page 6 of 6 — ← Prev page 1 2 3 4 5 [6]
| From | Robert Wessel <robertwessel2@yahoo.com> |
|---|---|
| Date | 2017-02-16 05:05 -0600 |
| Message-ID | <ko1bac95jdsfvnbilvf4uenkvg94bqbh3d@4ax.com> |
| In reply to | #103922 |
On Wed, 15 Feb 2017 09:47:29 +0100, David Brown <david.brown@hesbynett.no> wrote: >On 15/02/17 00:58, Robert Wessel wrote: >> On Tue, 14 Feb 2017 18:36:20 +0000, BartC <bc@freeuk.com> wrote: >> >>> People say that a C compiler is independent of any set of headers, >> >> >> Independent of any particular set, yes, but headers and compiler must >> be designed to work together. Which perfectly allows headers that >> work with multiple compilers, and compilers that work with multiple >> sets of headers, both of those simultaneously, or compilers and >> headers only have single (existing) partners they work with. What's >> not required is that all compilers work with all headers. >> >> In fact the standard *requires* that the headers and compilers >> understand each others *unspecified* behavior well enough to implement >> things like the offsetof macro. >> > >I think it is more correct to say requires that the headers and >compilers understand each others behaviour beyond that standards-defined >behaviour well enough to implement things like the offset macro. There >is certainly no need for the behaviour to be unspecified in general - >merely that it is undefined by the C standards. Which is really what I was intending to say. Although the required magic incantation might be known only to the library developers who are specifically blessed by the compiler developers.
[toc] | [prev] | [next] | [standalone]
| From | Tim Rentsch <txr@alumni.caltech.edu> |
|---|---|
| Date | 2017-02-15 16:53 -0800 |
| Message-ID | <kfnh93v0xdb.fsf@x-alumni2.alumni.caltech.edu> |
| In reply to | #103799 |
BartC <bc@freeuk.com> writes: > On 13/02/2017 13:09, Tim Rentsch wrote: >> BartC <bc@freeuk.com> writes: >> >>> X sees: extern int B; // from #include "X.h" >>> X contains: int B; // >>> >>> Y sees: extern int B; // from #include "X.h" >>> Z sees: extern int B; // from #include "X.h" >> >> This pattern, or one very similar to it, is used by all sensible >> C programmers. >> >>> This combination I can understand. However no one else seems to >>> write C like I do!) >> >> Lots of people do write C using a pattern like the one you show >> above. Is it really true that you don't see that in any of the C >> code you look at that is written by other people? If so it would >> be interesting to know what programs those are, they sound >> unusual to say the least. > > Actually it's difficult to tell, since a lot of examples I've just > looked at hide declarations behind horrendous looking multi-level > macros. So CPython's 40,000 lines of headers only have some 60 > occurrences of plain 'extern'. > > At least, gcc's stdio.h seems to use them directly: > > extern > __attribute__((__format__ (gnu_printf, 3, 0))) __MINGW_ATTRIB_NONNULL(3) > int __cdecl __mingw_vsnprintf(char * __restrict__ _DstBuf,size_t > _MaxCount,const char * __restrict__ _Format, > va_list _ArgList); Generally any implementation-specific system header is a bad place to look for representative examples. I understand that, for what you want to do, it is important to deal with the horrible junk that's in some system headers. But even though you need to look at it, it shouldn't be seen as representative. I have no experience with source code for python that I recall. Based on your description it doesn't sound representative either, but that could be a function of the programming style used, eg, never using any inter-TU global variables would mean fewer 'extern's needed. For comparison, I looked though some of the .h files in the source code for emacs. Picking one of the larger ones more or less at random, it looks pretty much like regular C code and doesn't have any of the crap like that shown above. There are roughly 23,000 lines in 47 .h files, with just over 1600 uses of 'extern'.
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2017-02-10 23:55 +0000 |
| Message-ID | <87h941zjlr.fsf@bsb.me.uk> |
| In reply to | #103636 |
Andrey Tarasevich <andreytarasevich@hotmail.com> writes: > On 2/10/2017 9:16 AM, BartC wrote: >> I've been trying to find out what the point of 'extern' is. >> >> Usually, if you declare: >> >> int abc; >> >> at filespec in modules A and B, then you end up with one copy of 'abc' >> shared across both modules. It doesn't matter which of A or B is abc's >> 'home' module. > > No, you will end up with a constraint violation. C language prohibits > this, although it lists it as a "popular extension" in a non-normative > appendix of the language standard. Nit: it's not a constraint violation. There's a constraint violation about multiple definitions of identifiers with internal linkage (para. 3 of section 6.9), but the "no more than one definition" rule for identifiers with external linkage is in the semantics section (para. 5). <snip> -- Ben.
[toc] | [prev] | [next] | [standalone]
| From | Les Cargill <lcargill99@comcast.com> |
|---|---|
| Date | 2017-02-10 19:24 -0600 |
| Message-ID | <o7lor7$8rf$1@dont-email.me> |
| In reply to | #103611 |
BartC wrote: > I've been trying to find out what the point of 'extern' is. > > Usually, if you declare: > > int abc; > > at filespec in modules A and B, then you end up with one copy of 'abc' > shared across both modules. It doesn't matter which of A or B is abc's > 'home' module. > > If one of them uses 'extern', then it's the same. But it fails when both > use 'extern'. > > Unless one (or both) modules has a second declaration with just 'int > abc;'; that seems to have the effect of cancelling 'extern'. So it must > be doing something, but what? > > When abc is initialised, then this is fine too (unless you initialise > the declaration with 'extern'), but now only one module can initialise > it; initialising both causes link errors. > > It seems that most of the time you can get by without 'extern'. So when > is it necessary? > IMO, as a nod to those who follow you, it is always necessary. A good toolchain ( again, IMO ) should think you've had an unintentional name collision and throw an error. -- Les Cargill
[toc] | [prev] | [next] | [standalone]
| From | void <nathan.gothier@gmail.com> |
|---|---|
| Date | 2017-02-11 03:17 -0800 |
| Message-ID | <bd675be9-1b55-46eb-ac4f-d090eaa826ec@googlegroups.com> |
| In reply to | #103611 |
On Friday, February 10, 2017 at 6:16:55 PM UTC+1, Bart wrote: > I've been trying to find out what the point of 'extern' is. > > Usually, if you declare: > > int abc; > > at filespec in modules A and B, then you end up with one copy of 'abc' > shared across both modules. It doesn't matter which of A or B is abc's > 'home' module. > > If one of them uses 'extern', then it's the same. But it fails when both > use 'extern'. > > Unless one (or both) modules has a second declaration with just 'int > abc;'; that seems to have the effect of cancelling 'extern'. So it must > be doing something, but what? > > When abc is initialised, then this is fine too (unless you initialise > the declaration with 'extern'), but now only one module can initialise > it; initialising both causes link errors. > > It seems that most of the time you can get by without 'extern'. So when > is it necessary? > > -- > Bartc You should understand the "linkage" concept related to identifiers scope. The "extern" keyword points to the outer definition of the identifer. That's the case for a function prototype declared in a header for example, because the function definition is outside the file scope.
[toc] | [prev] | [standalone]
Page 6 of 6 — ← Prev page 1 2 3 4 5 [6]
Back to top | Article view | comp.lang.c
csiph-web