通过一个例子说明C语言如何初始化静态变量。
给出C语言代码例子
这个例子在linux gcc x86_64环境下验证。
typedef int (* Fun)(void * obj, int argc, int *argv);
struct FunctionSpec {
const char *name; /* 8 byte */
Fun call; /* 8 byte */
unsigned char nargs; /* 1 byte */
unsigned char flags; /* 1 byte*/
unsigned short extra; /* 2 byte */
};
static int foo1(void *obj, int argc, int *argv) { return 0; }
static int foo2(void *obj, int argc, int *argv) { return 0; }
static int foo3(void *obj, int argc, int *argv) { return 0; }
static struct FunctionSpec my_functions[] = {
{"foo1", foo1, 11, 22, 33},
{"foo2", foo2, 44, 55},
{"foo3", foo3, 66},
{0}
};
int main(int argc, char * argv[])
{
printf("sizeof FunctionSpec=%d\n", sizeof(struct FunctionSpec