When compiling below code using GCC 4.8.3, I am getting an error saying "arrTest.c:12:4: error: variable-sized object may not be initialized". But the same code compiles fine when compiled with GCC 4.1. Can anyone help me to fix this?
#define OFFSET(structure, member) /* byte offset of member in structure*/\
((const int) &(((structure *) 0) -> member))
typedef struct test{
int a;
char b;
int c;
}test;
void main()
{
int arr[OFFSET(test, b)] = {0};
printf("%d %d\n", arr[0], OFFSET(test, b));
return;
}
Though, removing the array initialization would fix the problem. But, there are lot of instances like this in my code. So i don't want to go every where and modify. I wanted to know if there exists any way in GCC 4.8 to fix this either through some compilation flags or modifying the definition of the MACRO, as the same code gets compiled cleanly with GCC 4.1.
int arr[OFFSET(test, b)] = {0};toint arr[OFFSET(test, b)];