diff --git a/content/c-vla.md b/content/c-vla.md index 9640cf2..9b140c9 100644 --- a/content/c-vla.md +++ b/content/c-vla.md @@ -21,15 +21,6 @@ only at runtime, useful for algorithms where the size depends on function parame ```c #include -void print_matrix(int rows, int cols, int matrix[rows][cols]) { - for (int i = 0; i < rows; i++) { - for (int j = 0; j < cols; j++) { - printf("%3d ", matrix[i][j]); - } - printf("\n"); - } -} - int main(void) { int n = 3; int arr[n]; // VLA with runtime size @@ -41,8 +32,5 @@ int main(void) { for (int i = 0; i < n; i++) printf("%d ", arr[i]); printf("\n"); - - int matrix[2][3] = {{1, 2, 3}, {4, 5, 6}}; - print_matrix(2, 3, matrix); } ``` diff --git a/content/c-vm-types.md b/content/c-vm-types.md new file mode 100644 index 0000000..2c806f2 --- /dev/null +++ b/content/c-vm-types.md @@ -0,0 +1,36 @@ +--- +execute: true +show_assembly: true +flags: "-std=c99" +--- + +## What It Does + +Variably-modified types are types of variable-length arrays or types derived from VLAs, +e.g. pointers to VLAs or multi-dimensional arrays types where some dimension is variable. + +## Why It Matters + +Variably-modified types encode the number of elements of arrays in their type. This +allows convenient indexing into multi-dimenional arrays, recovery of the number of +elements from the type, and enables improved static analysis and automatic bounds checking. + +## Example + +```c +#include + +void print_matrix(int rows, int cols, int matrix[rows][cols]) { + for (int i = 0; i < rows; i++) { + for (int j = 0; j < cols; j++) { + printf("%3d ", matrix[i][j]); + } + printf("\n"); + } +} + +int main(void) { + int matrix[2][3] = {{1, 2, 3}, {4, 5, 6}}; + print_matrix(2, 3, matrix); +} +``` diff --git a/features_c23.yaml b/features_c23.yaml index 35222cb..bf7ad87 100644 --- a/features_c23.yaml +++ b/features_c23.yaml @@ -73,9 +73,13 @@ features: paper: N2508 support: - GCC 11 - - Clang 16 + - Clang 16 (partial) + - Clang 18 - MSVC (partial) - Xcode 15 + hints: + - target: Clang 16 + msg: "Only labels at the end of a block are supported" - desc: "[Binary integer constants](https://en.cppreference.com/w/c/language/integer_constant.html)" paper: N2549 content: c-binary-literals.md @@ -186,6 +190,13 @@ features: - GCC 14 - Clang 15 - Xcode 16.1 + - desc: "Require support for variably modified types" + paper: N2778 + support: + - GCC + - Clang + - Xcode + - TinyCC 0.9.28 - desc: "`__has_include` in preprocessor conditionals" paper: N2799 support: @@ -210,12 +221,12 @@ features: paper: N2900 content: c-empty-init.md support: - - GCC 13 (partial) + - GCC 13 - Clang (partial) - Xcode (partial) hints: - target: GCC 13 - msg: "Supported as an extension. Missing support for scalars and variable-length arrays (VLAs)." + msg: "Partially supported as an extension before." - target: Clang msg: "Supported as an extension. Missing support for scalars and variable-length arrays (VLAs)." - target: Xcode @@ -326,3 +337,10 @@ features: - GCC 13 - Clang 16 (partial) - Xcode 16.1 + - desc: "Partial program correctness" + paper: N3128 + support: + - GCC (partial) + hints: + - target: GCC + msg: "Not guaranteed for volatile accesses" diff --git a/features_c2y.yaml b/features_c2y.yaml index ce9aa38..b2d6eb1 100644 --- a/features_c2y.yaml +++ b/features_c2y.yaml @@ -269,9 +269,6 @@ features: - GCC 16 - Xcode 16.4 - - desc: "`auto` as placeholder type for parameters" - paper: N3472 - - desc: "Slay Some Earthly Demons XIII" paper: N3478 support: @@ -313,8 +310,10 @@ features: - desc: "Member access of an incomplete object" paper: N3532 support: + - GCC + - MSVC - Clang - - Xcode 16.4 + - Xcode - desc: "Chasing Ghosts I: constant expressions" paper: N3558 @@ -339,6 +338,7 @@ features: - desc: "Earthly Demon XV: Definition of Main" paper: N3623 support: + - GCC - Clang - Xcode ? diff --git a/features_c99.yaml b/features_c99.yaml index 3eae9bf..2d531ef 100644 --- a/features_c99.yaml +++ b/features_c99.yaml @@ -68,11 +68,14 @@ features: - Clang - Xcode 14 - TinyCC - - desc: "Variably-modified (VM) types" - paper: N2778 + - desc: "[Variably-modified](https://en.cppreference.com/w/c/language/array.html#Variable-length_arrays) (VM) types" + paper: N683 + content: c-vm-types.md support: + - GCC - Clang - Xcode + - TinyCC 0.9.28 - desc: "Designated initializers" paper: N494 content: c-designated-init.md