bug-standards
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ISO opposes variable-length arrays???


From: Paul Eggert
Subject: Re: ISO opposes variable-length arrays???
Date: Tue, 15 Oct 2024 00:49:10 -0500
User-agent: Mozilla Thunderbird

On 10/14/24 22:02, Richard Stallman wrote:
   > ! Second, because C11 no longer requires support for variable length
   > ! arrays,

Can you tell us what's behind this?  Is there some practical problem
caused by supporting variable-length arrays?

I don't know why C11 made VLAs optional. However, I can guess:

A. VLAs make code less safe, due to problems with stack overflow and related issues. There is no portable way for a program to detect and recover from memory exhaustion, and indeed in many implementations (including default GNU, if I'm not mistaken) the system does not even detect memory exhaustion reliably - the program merely has undefined behavior instead. This dangerous behavior is particularly important in multithreaded apps where each thread has a relatively small stack.

B. They make code a bit slower.

C. I vaguely recall there would be some technical issues in making C code with VLAs interoperate with C++. I don't use C++, though, so am not the best person to explain this.

If I had to guess, I would guess (A) was the most important of these issues.

The (A) problems afflict only block-scope VLAs. Many GNU programs avoid block-scope VLAs, at least partly for this reason. Other VLA usage (e.g., as array declarations in function prototype scope) don't have the (A) problems and should be OK to use in code not intended to be portable to non-GCC compilers.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]