使用现代C编译器的uu STDC _IEC u 559 uuu的现状
C99增加了一个宏使用现代C编译器的uu STDC _IEC u 559 uuu的现状,c,gcc,floating-point,clang,ieee-754,C,Gcc,Floating Point,Clang,Ieee 754,C99增加了一个宏\uuuuuuStDC\uIEC\u559\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu,可用于测试编译器和标准库是否符合ISO/IEC/IEEE 60559(或IEEE 754) 根据这个问题的答案 大多数C编译器不设置预处理器宏\uuuu STDC\uu IEC\uu559\uuu /* glibc's intent is to support the IEC 559 math functionality,
\uuuuuuStDC\uIEC\u559\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
,可用于测试编译器和标准库是否符合ISO/IEC/IEEE 60559(或IEEE 754)
根据这个问题的答案大多数C编译器不设置预处理器宏
\uuuu STDC\uu IEC\uu559\uuu
/* 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
它没有定义\uuuuuuuu STDC\uuu IEC\uuu559\uuuuuu
/* 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
我使用GCC4.9.2和Clang3.6.0测试了这一点,这两个版本都使用了glibc
2.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
}
这表明,在该代码中,\uuuu STDC\uu IEC\u559\uuuu
是用GCC定义的,而不是用Clang定义的。然后我做了gcc-E
,它显示了文件stdc predef.h
。该文件定义了\uuuuuustdc\uuiec\uu559\uuuuuu
/* 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
这证实了定义这个宏的是glibc而不是GCC
但是,当我包括features.h
(或stdio.h
)时,这个文件也会被Clang包含,并且定义了\uu STDC\u IEC\u559\uuu
因此,GCC和Clang(带有glibc
头文件)都定义了\uu STDC\u IEC\u 559\uuuuu
,这似乎与我链接到的第一个问题的答案不一致
然后我测试了(例如,musl-gcc-test.c
),这是一个与glibc
不同的标准库。这表明\uu STDC\u IEC\u 559\uu
未使用musl
定义
据我所知,标准C库并没有定义基本的浮点代数。例如,标准C库没有定义1.0/-0.0
的结果。这是由编译器定义的
我的问题是(按重要性排序):
\uuu STDC\u IEC\u 559\uuu
由glibc
定义,而不是由编译器定义\uuuu STDC\uu IEC\u559\uuuu
,那么我需要知道编译器已经符合IEEE 754,用于我的标准库中未定义的操作(例如1.0/-0.0
)。是否有此文档或宏用于测试\uu STDC\u IEC\u 559\uuu
)有时是定义的,但不应该定义。”。这句话还准确吗\uu STDC\u IEC\u 559\uu
依赖于一些库功能,不能仅由编译器定义。有关详细信息,请参阅。这在C语言中并不少见——编译器和C库有时必须合作才能实现整个标准\uuuugcc\uiec\u559
\ugcc\uiec\u559
MinGW不定义宏。我不知道为什么。@这个,那个很有趣。你是说明威64还是明威?他们是不同的。我还用gcc-m32 test.C尝试了32位模式,并且仍然定义了
\uu STDC\u IEC\u 559\uuu
。@Zboson对不起,我是说w64。@我认为w64更有趣。包含
时会发生什么情况。使用gcc-E怎么样?stdc predef.h
是否包含过?@Zboson功能不适用于c-E没有效果,为什么会呢?我不这么认为。\uuGCC\uIEC\u559
不是由GCC 4.9.2在我的问题中的test.c定义的,但是\uUSTDC\uIEC\u559\uU9
是定义的。我应该在我的问题中提到这一点。如果定义了\uugcc\uiec\u559
,那就更有意义了。关于我的第三个问题,我想这是我的问题。但那是2005年的事…很久以前的事了。