Home > Article > Backend Development > Do Variable Length Arrays (VLAs) Exist in C ?
Variable Length Arrays in C
Despite the common assumption that C does not support variable length arrays (VLAs), there are ways to achieve similar functionality. However, it's important to note that using these methods is not guaranteed compatibility across all compilers.
Code Explanation
The example code you provided compiles and works because:
Standard Support
It's important to note that the C standard does not require compilers to support VLAs. Therefore, code that uses VLAs may not be portable across different compilers or platforms.
Failed Proposal for C 14 and C 17
It was initially proposed that VLAs would be included in the C 14 standard. However, the proposal did not pass the voting process, and VLAs were not added to the language. The proposal also failed to be accepted for inclusion in C 17.
Conclusion
While VLAs are not officially part of the C standard, they can be used as an extension in certain compilers, such as GCC. However, it's crucial to be aware of potential portability issues and use VLAs with caution, especially in cross-platform code.
The above is the detailed content of Do Variable Length Arrays (VLAs) Exist in C ?. For more information, please follow other related articles on the PHP Chinese website!