使用现代C编译器的uu STDC _IEC u 559 uuu的现状

使用现代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,

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, 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库有时必须合作才能实现整个标准

  • 你问的问题取决于编译器。我认为你必须对编译器有专门的知识才能决定这个问题。在GCC的特定情况下,它定义了一个宏来告诉您。搜索
    \uuuugcc\uiec\u559

  • 嗯。。。我不知道这个问题的答案:-)。最初的帖子似乎表明,是的,如果GCC打算实施IEEE 754,即使它实际上没有这样做,它可能会定义
    \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年的事…很久以前的事了。