Re: Two questions on arrays with size defined by variables

Liste des GroupesRevenir à cl c 
Sujet : Re: Two questions on arrays with size defined by variables
De : janis_papanagnou+ng (at) *nospam* hotmail.com (Janis Papanagnou)
Groupes : comp.lang.c
Date : 09. Feb 2025, 18:17:45
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <voanvq$o6uh$1@dont-email.me>
References : 1 2 3 4
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0
On 09.02.2025 11:25, Keith Thompson wrote:
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. [...]

Thanks. (Again answering more/something different than I asked.) :-)

Please note that I structurally illustrated just the posters question
about where the relevant code excerpt resides (file scope or else).

If I'd knew the audience is picky I'd posted the whole test program;
but then there's even much more picky comments to expect. ;-)

I hope to mollify the audience if I point out that my code actually
looks *like* this

  ...
  int main (int argc, char * argv[])
  {
      ...
      return 0;
  }

(And, yes, I know that the "..." is not correct, and argc is unused,
and I omitted 'const', etc.)

[...] but that's not relevant to your example).

Right.

 
[...]
 
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.

Thanks!

Janis


Date Sujet#  Auteur
9 Feb 25 * Two questions on arrays with size defined by variables45Janis Papanagnou
9 Feb 25 `* Re: Two questions on arrays with size defined by variables44Andrey Tarasevich
9 Feb 25  +* Re: Two questions on arrays with size defined by variables41Janis Papanagnou
9 Feb 25  i+* Re: Two questions on arrays with size defined by variables10Keith Thompson
9 Feb 25  ii`* Re: Two questions on arrays with size defined by variables9Janis Papanagnou
10 Feb 25  ii `* Re: Two questions on arrays with size defined by variables8Keith Thompson
10 Feb 25  ii  `* Re: Two questions on arrays with size defined by variables7Janis Papanagnou
10 Feb 25  ii   +- Re: Two questions on arrays with size defined by variables1James Kuyper
10 Feb 25  ii   `* Re: Two questions on arrays with size defined by variables5Andrey Tarasevich
10 Feb 25  ii    `* Re: Two questions on arrays with size defined by variables4Janis Papanagnou
10 Feb 25  ii     `* Re: Two questions on arrays with size defined by variables3Keith Thompson
10 Feb 25  ii      `* Re: Two questions on arrays with size defined by variables2Janis Papanagnou
10 Feb 25  ii       `- Re: Two questions on arrays with size defined by variables1Keith Thompson
9 Feb 25  i+* Re: Two questions on arrays with size defined by variables6Michael S
9 Feb 25  ii`* Re: Two questions on arrays with size defined by variables5Janis Papanagnou
9 Feb 25  ii `* Re: Two questions on arrays with size defined by variables4Michael S
9 Feb 25  ii  +- Re: Two questions on arrays with size defined by variables1Janis Papanagnou
10 Feb 25  ii  `* Re: Two questions on arrays with size defined by variables2Keith Thompson
10 Feb 25  ii   `- Re: Two questions on arrays with size defined by variables1Janis Papanagnou
9 Feb 25  i+* Re: Two questions on arrays with size defined by variables20Waldek Hebisch
9 Feb 25  ii`* Re: Two questions on arrays with size defined by variables19Janis Papanagnou
9 Feb 25  ii +* Re: Two questions on arrays with size defined by variables13Andrey Tarasevich
9 Feb 25  ii i`* Re: Two questions on arrays with size defined by variables12Janis Papanagnou
9 Feb 25  ii i +* Re: Two questions on arrays with size defined by variables7Janis Papanagnou
9 Feb 25  ii i i`* Re: Two questions on arrays with size defined by variables6James Kuyper
10 Feb 25  ii i i +- Re: Two questions on arrays with size defined by variables1Waldek Hebisch
10 Feb 25  ii i i `* Re: Two questions on arrays with size defined by variables4Janis Papanagnou
10 Feb 25  ii i i  `* Re: Two questions on arrays with size defined by variables3David Brown
10 Feb 25  ii i i   `* Re: Two questions on arrays with size defined by variables2Janis Papanagnou
10 Feb 25  ii i i    `- Re: Two questions on arrays with size defined by variables1David Brown
9 Feb 25  ii i `* Re: Two questions on arrays with size defined by variables4Michael S
10 Feb 25  ii i  `* Re: Two questions on arrays with size defined by variables3Opus
10 Feb 25  ii i   `* Re: Two questions on arrays with size defined by variables2Michael S
10 Feb 25  ii i    `- Re: Two questions on arrays with size defined by variables1Opus
10 Feb 25  ii `* Re: Two questions on arrays with size defined by variables5Keith Thompson
10 Feb 25  ii  `* Re: Two questions on arrays with size defined by variables4Janis Papanagnou
10 Feb 25  ii   `* Re: Two questions on arrays with size defined by variables3Janis Papanagnou
10 Feb 25  ii    `* Re: Two questions on arrays with size defined by variables2Keith Thompson
10 Feb 25  ii     `- Re: Two questions on arrays with size defined by variables1Janis Papanagnou
9 Feb 25  i+* Re: Two questions on arrays with size defined by variables3Andrey Tarasevich
9 Feb 25  ii+- Re: Two questions on arrays with size defined by variables1Janis Papanagnou
9 Feb 25  ii`- Re: Two questions on arrays with size defined by variables1James Kuyper
9 Feb 25  i`- Re: Two questions on arrays with size defined by variables1James Kuyper
9 Feb 25  +- Re: Two questions on arrays with size defined by variables1James Kuyper
15 Feb17:19  `- Re: Two questions on arrays with size defined by variables1Tim Rentsch

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal