Skip to content

Instantly share code, notes, and snippets.

@weskerfoot
Created February 9, 2021 23:57
Show Gist options
  • Save weskerfoot/fe88805e544b44f71e88c76e5c0b5566 to your computer and use it in GitHub Desktop.
Save weskerfoot/fe88805e544b44f71e88c76e5c0b5566 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
struct Foo {
int a;
int arr[];
};
struct Foo*
f(int n) {
struct Foo *a = calloc(sizeof *a, n * sizeof (int));
a->a = 42;
a->arr[n] = 666;
a[1].arr[n+2] = 420;
a[n].arr[n] = 420666;
return a;
}
int
main() {
struct Foo *test = f(12);
printf("%d\n", test[12].arr[12]);
free(test);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment