You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: manual.md
+1-63Lines changed: 1 addition & 63 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -258,7 +258,7 @@ In C99/C23, there are two related but distinct concepts:
258
258
- **VM types** (`int (*p)[n]`) - any type derived from a runtime-sized array, including pointers to VLAs. **Mandatory** in C23 even when `__STDC_NO_VLA__` is defined.
259
259
260
260
Cake supports **VM types** and converts them to C89-compatible code.
261
-
Cake does **not** support VLA objects - a diagnostic is emitted instead, pointing to the VM type alternative.
261
+
Cake does **not** support VLA objects.
262
262
263
263
#### VM type pointer declarations
264
264
@@ -278,68 +278,6 @@ int main() {
278
278
```
279
279
<buttononclick="Try(this)">try</button>
280
280
281
-
The C89 output captures the dimensions into snapshot variables at declaration time,
282
-
so that later mutation of `n` or `m` does not affect the allocation size or `sizeof` results:
283
-
284
-
```c
285
-
int __v0;
286
-
int __v1;
287
-
int *p;
288
-
__v0 = (n);
289
-
__v1 = (m);
290
-
p = (int *)malloc(sizeof(int) * __v0 * __v1);
291
-
printf("%zu\n", (sizeof(int) * __v0 * __v1));
292
-
free(p);
293
-
```
294
-
295
-
#### VM type function parameters
296
-
297
-
VM pointer parameters are also rewritten to flat pointers. Subscript expressions
298
-
through the pointer are linearised automatically.
299
-
300
-
```c
301
-
#include <stdlib.h>
302
-
#include <stdio.h>
303
-
304
-
void fill(int n, int m, int (*grid)[n][m])
305
-
{
306
-
int i, j;
307
-
for (i = 0; i < n; i++)
308
-
for (j = 0; j < m; j++)
309
-
(*grid)[i][j] = i * 10 + j;
310
-
}
311
-
312
-
int main() {
313
-
int n = 3, m = 4;
314
-
int (*p)[n][m] = malloc(sizeof *p);
315
-
fill(n, m, p);
316
-
free(p);
317
-
}
318
-
```
319
-
<buttononclick="Try(this)">try</button>
320
-
321
-
C89 output for `fill`:
322
-
323
-
```c
324
-
voidfill(int n, int m, int *grid)
325
-
{
326
-
int i, j;
327
-
for (i = 0; i < n; i++)
328
-
for (j = 0; j < m; j++)
329
-
((int*)grid)[(i) * m + (j)] = i * 10 + j;
330
-
}
331
-
```
332
-
333
-
#### VLA objects are not supported
334
-
335
-
```c
336
-
int main() {
337
-
int n = 5;
338
-
int a[n]; /* error: variable length arrays are not supported;
0 commit comments