我已经宣布了这一系列的工会:
union Function {
char* name;
double (*fnct)();
int args;
};
union Function functions[] = {
{.name = "acos", .fnct = acos, .args = 1},
{.name = "asin", .fnct = asin, .args = 1},
{.name = "atan", .fnct = atan, .args = 1},
};
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试使用它时,我得到一个Segmentation fault错误.
for(int i = 0; i < sizeof(functions) / sizeof(union Function); i++) {
printf("%d\n", functions[i].args);
printf("%s\n", functions[i].name); //HERE!
}
Run Code Online (Sandbox Code Playgroud)