我只是想知道,如果我有一个接受其中包含 union 的结构的函数,我如何知道该 union 的内容:
struct command{
int *input;
int *output;
union{
char **word;
struct command *subcommand;
} u;
};
函数:
void readCommand(command cInput){
if(cInput.u is char) print the content of array of array of char
else readCommand(cInput.u); //make a recursive call
}
有什么建议吗?谢谢
注意:我无法更改struct 命令的内容。
最佳答案
你不能。这就是 union 的本质。如果需要,您必须将 union 嵌入到结构中,并在结构中放置类型指示符。
关于c - 如何区分union的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17384588/