Deutsch   English   Français   Italiano  
<vob2fo$q3rn$1@dont-email.me>

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

Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: James Kuyper <jameskuyper@alumni.caltech.edu>
Newsgroups: comp.lang.c
Subject: Re: Two questions on arrays with size defined by variables
Date: Sun, 9 Feb 2025 15:16:54 -0500
Organization: A noiseless patient Spider
Lines: 22
Message-ID: <vob2fo$q3rn$1@dont-email.me>
References: <vo9mns$gsd7$1@dont-email.me> <vo9nn3$gtph$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 09 Feb 2025 21:16:57 +0100 (CET)
Injection-Info: dont-email.me; posting-host="747f909815c9273d0d3564426e08bd23";
	logging-data="855927"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1/HHcboBOCWnTSh/HJfYYfu42O4ftxPyPs="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:Z1nx/pkqajVOotyg5xranUANMos=
Content-Language: en-US
In-Reply-To: <vo9nn3$gtph$1@dont-email.me>
Bytes: 1896

On 2/9/25 03: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];
>>    ...
>>
>> 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.

While that is correct, it's incomplete. The relevant constraint is
"If an identifier is declared to be an object with static or thread
storage duration, it shall not have a variable length array type."
(6.7.6.2p2).

All objects declared at file scope have static storage duration, but
that rule also applies to objects objects declared at block scope if
they are declared with the "static" or "thread_local" keywords.