gpt4 book ai didi

c - 如何区分union的内容

转载 作者:太空宇宙 更新时间:2023-11-04 04:49:22 25 4
gpt4 key购买 nike

我只是想知道,如果我有一个接受其中包含 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com