Liste des Groupes | Revenir à cl c |
Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:[...]On 09.02.2025 09:06, Andrey Tarasevich wrote:
But a function body is in itself a block. Inside a function body you are>
already in "a block context".
>Anyway. I tried it without function or block context>
>
int n = 5;
char * arr[n];
...
>
and it seemed to work seamlessly like that (with GNU cc, -std=C99).
You mean you did this at file scope? No, VLAs are illegal at file scope.
And I was unable to repeat this feat in GCC.
Oh, sorry, no; above I had just written an excerpt. - Actually I had
those two examples above within a main() function. - Sorry again for
my inaccuracy.
>
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];
...
}
The first line needs to be `int main(void)`. The "implicit int"
misfeature was removed in C99. [...]
[...] but that's not relevant to your example).
[...]
C90 didn't have VLAs at all.
C99 introduced them and required all implementations to support them.
C11 made variably modified types optional.
C23 still makes variable length arrays with automatic storage duration
optional but "Parameters declared with variable length array types are
adjusted and then define objects of automatic storage duration with
pointer types. Thus, support for such declarations is mandatory."
(Support for C23 is still preliminary.)
For my purpose it would be okay to know whether with the C99 version
(that I used) it's okay, or whether that's some GNU specific extension
or some such.
C99 requires support for local objects of variable length array types.
Les messages affichés proviennent d'usenet.