Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions content/c-vla.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,6 @@ only at runtime, useful for algorithms where the size depends on function parame
```c
#include <stdio.h>

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
Expand All @@ -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);
}
```
36 changes: 36 additions & 0 deletions content/c-vm-types.md
Original file line number Diff line number Diff line change
@@ -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 <stdio.h>

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);
}
```
24 changes: 21 additions & 3 deletions features_c23.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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"
8 changes: 4 additions & 4 deletions features_c2y.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -339,6 +338,7 @@ features:
- desc: "Earthly Demon XV: Definition of Main"
paper: N3623
support:
- GCC
- Clang
- Xcode ?

Expand Down
7 changes: 5 additions & 2 deletions features_c99.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading