Deutsch   English   Français   Italiano  
<v9tcgb$2fdj5$1@dont-email.me>

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

Path: ...!weretis.net!feeder9.news.weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: David Brown <david.brown@hesbynett.no>
Newsgroups: comp.lang.misc
Subject: Re: C function prototype was Python (was Re: I did not inhale)
Date: Sun, 18 Aug 2024 19:54:19 +0200
Organization: A noiseless patient Spider
Lines: 52
Message-ID: <v9tcgb$2fdj5$1@dont-email.me>
References: <uu54la$3su5b$6@dont-email.me> <20240408075547.000061e8@gmail.com>
 <g52cnWOOwoz_son7nZ2dnZfqnPWdnZ2d@brightview.co.uk>
 <uvbe3m$2cun7$1@dont-email.me> <uvbfii$3mom0$1@news.xmission.com>
 <20240412094809.811@kylheku.com> <87il0mm94y.fsf@tudado.org>
 <way-20240413091747@ram.dialup.fu-berlin.de> <87il0lldf8.fsf@tudado.org>
 <choices-20240413123957@ram.dialup.fu-berlin.de>
 <v9lm2k$12qhv$1@dont-email.me> <v9m4gd$14scu$1@dont-email.me>
 <20240815182717.189@kylheku.com> <v9npls$1fjus$1@dont-email.me>
 <v9t204$2dofg$1@dont-email.me> <v9t7tn$2eiop$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 18 Aug 2024 19:54:19 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="dcf5933836487a5711ce49e3b1d68f43";
	logging-data="2602597"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX19bQSjsbPQljJbW77dGYur2VsIf9mGTwOg="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:YkPucpbVJvHnx8wcjmlllzV34n0=
In-Reply-To: <v9t7tn$2eiop$1@dont-email.me>
Content-Language: en-GB
Bytes: 3674

On 18/08/2024 18:36, James Harris wrote:
> On 18/08/2024 15:55, David Brown wrote:
> 
> ...
> 
>> What does "static" mean inside square brackets in a C function prototype?
> 
> I know there's a better newsgroup for it but, since you brought it up 
> and it does also fit here, I should say that I had no idea that a C 
> program could have square brackets in a function prototype and I cannot 
> think of ever seeing such a thing.
> 

I didn't mean we should go into detail about such features - it's just 
an example of a feature of the core language of C that most C 
programmers don't know about, and the lack of that knowledge does not 
prevent them being able to write code in C.  It is not a useful feature.

If you write "int foo(int xs[static 10]);", then it is undefined 
behaviour to call "foo" with an argument that does not point to an array 
of at least 10 elements (and it is therefore also UB to call it with a 
null pointer).  In theory, this could give a few more opportunities for 
static error checking or optimisation.  In practice, compilers will give 
you exactly the same checks and optimisations without the "static".

> I presume you do mean C and not some sort of compiler extension.

Yes.

> 
> As for static, IIRC labelling as "static" any external name (i.e. one 
> not in a function) would make it private to the CU and not visible 
> outside but that is just a guess.

It is also used for local variables in functions - these then have the 
same scope as another local variable in the same place, but have 
program-static lifetime.

But the use in array parameters is not related to either of these, and 
is IMHO a potentially confusing and basically useless additional use of 
the keyword.

(If anyone knows of it being useful in this context, please say so!)

> 
> Or perhaps you meant a static formal parameter. Again, not something 
> I've ever come across and would be curious as to what it meant.
> 
> Would you care to say more about what you had in mind?
> 
>