Sujet : Re: Two questions on arrays with size defined by variables
De : jameskuyper (at) *nospam* alumni.caltech.edu (James Kuyper)
Groupes : comp.lang.cDate : 09. Feb 2025, 21:27:29
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vob33h$q3rn$2@dont-email.me>
References : 1 2 3
User-Agent : Mozilla Thunderbird
On 2/9/25 04:54, Janis Papanagnou wrote:
On 09.02.2025 09:06, Andrey Tarasevich wrote:
On Sat 2/8/2025 11:50 PM, Janis Papanagnou wrote:
...
Anyway. I tried it without function or block context
>
int n = 5;
char * arr[n];
...
What I meant was (with surrounding context) that I knew (from _other_
languages) a syntax like
main ()
{
int n = 5;
{
char * arr[n];
...
}
}
And in "C" (C99) I tried it *without* the _inner block_
main ()
{
int n = 5;
char * arr[n];
...
}
You need to get more familiar with the relevant terminology. In C,
identifiers have a scope within which they may be used, and three of the
relevant kinds of scopes are "file scope", "function scope", and "block
scope". That's sufficiently similar to your mention of "function or
block context", to make people think that "context" might be meant as an
informal equivalent of "scope". That's why people assumed you were
talking about a file scope declaration.
The body of a function is a compound statement, which constitutes a
block. There is another, larger block that includes "The parameter type
list, [and] the attribute specifier sequence of the declarator that
follows the parameter type list, ...". Each of those two blocks has a
separate scope. Identifiers declared inside either of those blocks have
block scope.
"function scope" applies only to label names.