Skip to content

Instantly share code, notes, and snippets.

@io12
Last active August 23, 2017 19:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save io12/10a9edcad74d25a8c5987fe3a32cb604 to your computer and use it in GitHub Desktop.
Save io12/10a9edcad74d25a8c5987fe3a32cb604 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#define LEN(x) (sizeof(x) / sizeof(x[0]))
/*
* Declare `arr`, an array of four pointers to arrays of two function pointers
* to a function that accepts a pointer to a two by two two dimensional array
* of ints as a parameter and returns an int.
*/
int (*((*arr[4])[2]))(int (*)[2][2]);
int foo(int (*p)[2][2])
{
int i, j;
for (i = 0; i < LEN(*p); i++) {
for (j = 0; j < LEN((*p)[i]); j++) {
(*p)[i][j] = 1337;
}
}
return -1;
}
int main(void)
{
int i, j, (*p)[2][2];
for (i = 0; i < LEN(arr); i++) {
arr[i] = malloc(sizeof(*arr[i]));
for (j = 0; j < LEN(*arr[i]); j++) {
(*arr[i])[j] = foo;
p = malloc(sizeof(*p));
((*arr[i])[j])(p);
free(p);
}
}
puts("No segfault!");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment