c - 在C中返回联合的有效方法?
问题描述
我有一个返回联合的函数,调用者知道如何处理。有没有一种有效的单线方式来返回一个工会?我现在应该做什么:
typedef union { int i; char *s; double d; } FunnyResponse;
FunnyResponse myFunc () {
// Tedious:
FunnyResponse resp;
resp.d = 12.34;
return resp;
}
int main () {
printf ("It's this: %g\n", myFunc().d);
}
这会编译并运行,但是如果可能的话,我希望有一个“返回”行。有任何想法吗?
解决方案
推荐阅读
- c# - 如何在 {controller}/{action}/{id} 之前使用自定义路由获取值
- python - Function to input key and value from dictionary, extract line of data from given input location (csv file), and output the line of data
- node.js - (JWT) RSA Encryption/decryption issue
- javascript - 在 websocket api javascript 中使用回调函数
- google-apps-script - 如何使用 onclick=google.script.run.taxBill(this.value) 在循环的 Htmlservice 表中获取列值?
- c# - 如何在 Visual Studio 中阻止磁贴自动缩放
- javascript - 为什么这个 javascript 在 thymeleaf 的内联 javascript 标记中不起作用?语法有问题吗?
- python - 基于前一行的唯一行数 - Pandas
- javascript - 在 componentDidMount 之后根据 React State 设置输入值?
- reactjs - 将初始文件加载到材质 ui dropzone