Z b*_*son 27 c floating-point gcc clang ieee-754
C99添加了一个宏__STDC_IEC_559__,可用于测试编译器和标准库是否符合ISO/IEC/IEEE 60559(或IEEE 754)标准.
根据这个问题的答案,
如何检查-ieee-754-单精度-32位浮点表示,大多数C编译器不设置预处理器宏__STDC_IEC_559__.
根据海湾合作委员会的文件,它没有定义__STDC_IEC_559__.
我用GCC 4.9.2和Clang 3.6.0测试了这两个,使用glibc2.21使用以下代码.
//test.c
//#include <features.h>
int main(void) {
#if defined ( __STDC_IEC_559__ )
//#if defined ( __GCC_IEC_559__ )
return 1;
#else
return 0;
#endif
}
Run Code Online (Sandbox Code Playgroud)
然后
echo $?
Run Code Online (Sandbox Code Playgroud)
这表明此代码__STDC_IEC_559__是使用GCC定义的,而不是使用Clang定义的.然后我做了gcc -E,它显示该文件stdc-predef.h包含在内.这个文件定义__STDC_IEC_559__.
/* glibc's intent is to support the IEC 559 math functionality, real
and complex. If the GCC (4.9 and later) predefined macros
specifying compiler intent are available, use them to determine
whether the overall intent is to support these features; otherwise,
presume an older compiler has intent to support these features and
define these macros by default. */
#ifdef __GCC_IEC_559
# if __GCC_IEC_559 > 0
# define __STDC_IEC_559__ 1
# endif
#else
# define __STDC_IEC_559__ 1
#endif
Run Code Online (Sandbox Code Playgroud)
这证实了它glibc定义了这个宏而不是GCC.
但是,当我包含features.h(或stdio.h)时,Clang也会包含此文件并且__STDC_IEC_559__已定义.
所以__STDC_IEC_559__由GCC和Clang(带有glibc头文件)定义,这似乎不同意我链接到的第一个问题的答案.
然后我测试musl(例如musl-gcc -test.c)这是一个不同的标准库glibc.这表明__STDC_IEC_559__没有定义musl.
据我了解,标准C库没有定义基本的浮点代数.例如,标准C库没有定义结果1.0/-0.0.这是由编译器定义的.
我的问题是(按重要性顺序排列):
__STDC_IEC_559__定义glibc而不是由编译器定义?__STDC_IEC_559__我需要知道编译器已经符合IEEE 754标准库中未定义的操作(例如1.0/-0.0).是否有针对此或宏的文档进行测试?__STDC_IEC_559__)有时被定义,而它不应该是".这个陈述是否仍然准确?