Path: csiph.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From: Tim Rentsch
Newsgroups: comp.lang.c
Subject: Re: gcc and 'include'
Date: Mon, 30 Mar 2026 07:20:29 -0700
Organization: A noiseless patient Spider
Lines: 45
Message-ID: <86ikad1jrm.fsf@linuxsc.com>
References: <10q4ceb$38i2d$1@dont-email.me> <87ikaiw5g0.fsf@example.invalid> <10q5nnr$3l3lc$1@dont-email.me> <10q6snp$2nka$5@dont-email.me> <10q6uv4$419b$1@dont-email.me> <20260328203718.00005c70@yahoo.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Date: Mon, 30 Mar 2026 14:20:30 +0000 (UTC)
Injection-Info: dont-email.me; posting-host="2cd52f7e7f6c86e7548f05bf3bc2e07a"; logging-data="2644421"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX192kWeAEBW8M+6ttuOtMYPGexWxjDaW9VI="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:Jh1jRU4VfOspIxKErO3p17DcbAs= sha1:YkIGyBvp3Lw7tSESs2hZsC3yDOU=
Xref: csiph.com comp.lang.c:397306
Michael S writes:
> On Fri, 27 Mar 2026 22:05:24 +0000
> Bart wrote:
>
>> But, yeah, some C aspect being unintuitive is nothing new:
>>
>> extern int abc;
>> int abc = 123;
>>
>> Or:
>>
>> static int abc;
>> extern int abc;
>>
>> Both are valid C, but this isn't:
>>
>> extern int abc;
>> static int abc;
>>
>>
>> I dare not ask what the rules are; I'm sure they exist, but they
>> still don't make sense. I can only find out which of these are
>> valid or not by trial and error. A HLL shouldn't be like that.
>
> Why do you care?
> As C programmer, all you have to know is to never use either 2nd or
> 3rd, because even if one of them can be legal according to Standard,
> both of them certainly make no sense.
There are situations where an 'extern' declaration might reasonably
be preceded by a 'static' declaration (or definition). These days I
expect such situations don't arise very often, so people don't think
about it, but the rule is there for a reason.
> For your first example, it sometimes make sense, typically as result
> of #inclyde and/or marcro substitution. What exactly do you find
> unintuitive about it?
For global symbols, in 99+ percent of all cases, there should be
an 'extern' declaration in a .h file, and a definition without
the 'extern' in exactly one .c file. Informally, 'extern' means
"is defined somewhere but I'm not saying where", and leaving off
the 'extern' means "I'm defining it here". Speaking for myself I
don't find anything hard to understand or unintuitive about that.