I
InuY4sha
Hi list,
I already asked something similar: I have this code
#include <stdio.h>
void foo(void){ printf("helloworld\n"); return; }
void (* foo2)(void) = foo;
struct data {void (* fptr)(void);};
static struct data myarray[] = {
{foo},
{foo2}, //THIS must be commented for the code to work!!!!
};
int main(){myarray[0].fptr(); return 0; }
and THIS generates the following error:
test.c:7: error: initializer element is not constant
test.c:7: error: (near initialization for ‘myarray[1].fptr’)
Can I fix it by placing a "const" in the right position?
I was thinking to use "(* const foo2)" but it doesn't change a thing.
Thanks in advance
RM
I already asked something similar: I have this code
#include <stdio.h>
void foo(void){ printf("helloworld\n"); return; }
void (* foo2)(void) = foo;
struct data {void (* fptr)(void);};
static struct data myarray[] = {
{foo},
{foo2}, //THIS must be commented for the code to work!!!!
};
int main(){myarray[0].fptr(); return 0; }
and THIS generates the following error:
test.c:7: error: initializer element is not constant
test.c:7: error: (near initialization for ‘myarray[1].fptr’)
Can I fix it by placing a "const" in the right position?
I was thinking to use "(* const foo2)" but it doesn't change a thing.
Thanks in advance
RM