Skip to content

Instantly share code, notes, and snippets.

@theoknock
Created September 11, 2022 17:02
Show Gist options
  • Save theoknock/5010db64e9f3feb6131ea9670c06c6b8 to your computer and use it in GitHub Desktop.
Save theoknock/5010db64e9f3feb6131ea9670c06c6b8 to your computer and use it in GitHub Desktop.
Flexible *pointer* array members
typedef typeof(unsigned long (^ _Nonnull __strong (* _Nonnull))(unsigned long)) predicate_function_ptr;
struct predicate_functions_arr_struct
{
unsigned long len;
predicate_function_ptr functions[];
};
static void(^test_flexible_array_member)(void) = ^{
struct predicate_functions_arr_struct * p_functions = malloc(sizeof(struct predicate_functions_arr_struct) + (10 * sizeof(predicate_function_ptr)));
p_functions->len = 10;
for (unsigned long i = 0; i < p_functions->len; i++) {
(p_functions->functions[i] = Block_copy((typeof(unsigned long(^*)(unsigned long)))CFBridgingRetain(^ (unsigned long p) {
return ^ (unsigned long q) {
printf("\np == %lu\nq == %lu\n", p, q);
return p && q;
};
}(i))));
}
for (unsigned long i = 0; i < p_functions->len; i++) {
unsigned long(^pf)(unsigned long) = CFBridgingRelease((p_functions->functions[i]));
printf("pf[%lu] == %lu\n", i, pf(i));
}
};
// test_flexible_array_member();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment