Deutsch   English   Français   Italiano  
<vt94q5$3jjod$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: David Brown <david.brown@hesbynett.no>
Newsgroups: comp.lang.c
Subject: Re: do { quit; } else { }
Date: Thu, 10 Apr 2025 21:05:41 +0200
Organization: A noiseless patient Spider
Lines: 36
Message-ID: <vt94q5$3jjod$1@dont-email.me>
References: <vspbjh$8dvd$1@dont-email.me> <8634enhcui.fsf@linuxsc.com>
 <vsph6b$ce6m$5@dont-email.me> <86ldsdfocs.fsf@linuxsc.com>
 <20250406161323.00005809@yahoo.com> <86ecy5fjin.fsf@linuxsc.com>
 <20250406190321.000001dc@yahoo.com> <86plhodtsw.fsf@linuxsc.com>
 <20250407210248.00006457@yahoo.com> <vt15lq$bjs0$3@dont-email.me>
 <vt2lp6$1qtjd$1@dont-email.me> <vt31m5$2513i$1@dont-email.me>
 <vt3d4g$2djqe$1@dont-email.me> <vt3iqh$2ka99$1@dont-email.me>
 <vt5fed$ccri$1@dont-email.me> <vt5js2$g1t7$1@dont-email.me>
 <20250409142303.00004645@yahoo.com> <87ikndqabc.fsf@nosuchdomain.example.com>
 <20250410115501.000037a5@yahoo.com> <vt8ei8$2vn84$1@dont-email.me>
 <20250410080629.532@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 10 Apr 2025 21:05:43 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="084a311b0438af03b2b08f11cda96637";
	logging-data="3788557"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+H2a9Z4qwHHk0PiOQuLeNsHMkfYS/vWOk="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:tk/Ods0j/HL08WXMx1o5IU6ejEM=
In-Reply-To: <20250410080629.532@kylheku.com>
Content-Language: en-GB
Bytes: 3354

On 10/04/2025 17:41, Kaz Kylheku wrote:
> On 2025-04-10, David Brown <david.brown@hesbynett.no> wrote:
>> So currently, I have no explanation for why you may write "static int
>> foo; extern int foo;" and have "foo" be internal linkage, while "extern
>> int foo; static int foo;" is not allowed.
> 
> What's also not allowed is "static int foo; int foo;" !
> 
> It's because "extern" means "refer to the existing file scope
> declaration of the identifer if there is one propagating its
> properties, including linkage; otherwise if it doesn't exist,
> create an external linkage reference"
> 

That's a summary of how "extern" works, but it results in a kind of 
circular argument or tautology - it's just saying "extern means what it 
means".  It does not explain /why/ it works this way, or where the rules 
came from, why C has use of a single keyword that works this way, and 
why it is called "extern".

It would be much simpler if we had "static int x;" to mean "declare x 
with internal linkage and define it", "extern int x;" to mean "declare x 
to have extern linkage", and "int x;" to mean "declare x with external 
linkage and define it".  That is how you use these in most circumstances 
(and there are gcc warning flags to enforce it, for those that want to 
do that).

C rarely makes things more complicated without a good reason.  You gave 
the example of using "extern" for "unshadowing" an identifier (thank you 
for that example!), but it doesn't strike me as sufficient 
justification.  I had thought the reason for the way "extern" and 
"static" interact was historical compatibility, but that does not appear 
to be the case.