大佬教程收集整理的这篇文章主要介绍了C11_Generic将true和false推断为整数,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
#include <stdio.h> #include <stdbool.h> #define Typename(X) \ _Generic((X),\ bool: "bool",\ int: "int",\ default: "unkNown") #if Defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) && (__bool_true_false_are_defined) # undef true # define true ((bool)(1)) # undef false # define false ((bool)(0)) #endif int main(void) { printf("1: %s\n",Typename(1)); printf("true: %s\n",Typename(true)); printf("false: %s\n",Typename(false)); }
这打印:
1: int true: bool false: bool
但是没有重新定义真假的中间位:
1: int true: int false: int
这意味着您无法执行_Generic功能,例如:
struct Variant * const int32 = variant_create(1); struct Variant * const Boolean = variant_create(true);
所以我的问题是:
>重新定义片段是安全的吗?
>这是C11标准中的疏忽还是GCC和Clang中的@L_489_7@?
以上是大佬教程为你收集整理的C11_Generic将true和false推断为整数全部内容,希望文章能够帮你解决C11_Generic将true和false推断为整数所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。