You're not using the compound literal operator correctly.
In between the parentheses, only the type is meaningful. Declaring i as an int is completely useless. The compiler ignores i.
In between the curly brackets, you must give a value that matches the type enclosed in the preceding parentheses.
Examples:
Code:
(int) {23}
(char []) {"abc"}
(int (*)(int)) {print_add}
To make your code work,
Code:
#include <stdio.h>
#define break_code
int print_add(int i)
{
printf("%d\n", ++i);
return i;
}
int main(void)
{
enum { printadd = 0 };
int (*functions[1])(int) = {
#ifdef break_code
(int (*)(int)) {
print_add
}
#endif
};
// b will be 6
int b = functions[printadd](5);
printf("b = %d\n", b);
return 0;
}
However, using the compound literal operator is completely redundant here and wastes space as it allocates memory to store the function pointer.
So, instead,
Code:
#include <stdio.h>
#define break_code
int print_add(int i)
{
printf("%d\n", ++i);
return i;
}
int main(void)
{
enum { printadd = 0 };
int (*functions[1])(int) = {
#ifdef break_code
print_add
#endif
};
// b will be 6
int b = functions[printadd](5);
printf("b = %d\n", b);
return 0;
}