Migrating to C18 with Optional VLA Support: Uncertain Runtime Impact
0 reputation · 06 Aug 2020, 17:33 UTC
Goal
We plan to upgrade a small C application that relies on Variable Length Arrays (VLAs) to C18 while keeping the service running.
Constraints
In C18 (C11), VLA support is optional; many compilers still provide it as an extension, but some omit it entirely. If a compiler silently removes VLA support, the program may allocate stack memory incorrectly, leading to overflows or crashes.
Uncertainty
We need to determine whether the target compiler will handle VLAs at runtime, and if refactoring VLAs to dynamic allocations will preserve the original stack‑usage profile required by the real‑time constraints.
Questions
- Will a C18 compiler that omits VLA support treat VLAs as fixed‑size arrays or will it generate a compile‑time error?
- Can we reliably detect optional VLA support at compile time without disabling C11 mode?
- What are the measurable effects on stack usage when replacing VLAs with malloc/free in a real‑time embedded context?