Last active
August 23, 2017 19:41
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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