我是Java新手,来自Java背景.
如果我有一个动态初始化的结构,其中的数据来自结构定义中的函数,那么这些函数什么时候被调用?这段代码什么时候运行?它只是第一次参考sample_struct_table[i]?
static struct sample_struct {
int command;
int (*foo)( obj1 *banana, int num);
} sample_struct_table[] = {
{ .command = COMMAND_1,
.foo = function_name,
},
{ .command = COMMAND_2,
.foo = another_function_name,
},
};
static int function_name(obj1 *banana, int num)
{
// do stuff here
// When does this get called?
}
Run Code Online (Sandbox Code Playgroud)