M_PI不适用于gcc --std = c11,但使用--std = gnu11? [英] M_PI not available with gcc --std=c11 but with --std=gnu11?

查看:757
本文介绍了M_PI不适用于gcc --std = c11,但使用--std = gnu11?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到 M_PI c11 中不可用。通过查看 /usr/include/math.h 我可以看到 M_PI 是在以下情况下定义的:

  #if!defined(__ STRICT_ANSI__)|| ((_XOPEN_SOURCE_0)> = 500)
...
#define M_PI 3.1415 ...
#endif

此外,在 math.h from glibc __ STRICT_ANSI __ 被替换为 __ USE_MISC 。我完全失去了这一点。

- std = c11 中定义的常数之间有什么关系? math.h



其中 libc 应该考虑 debian distribution?



顺便说一句, M_PI c99 gnu11 ...

解决方案<这很简单: M_PI 未在标准C中定义。如果您希望符合标准,请提供您自己的定义。



C编译器无法在不破坏合法C程序的情况下引入这些常量(名称不保留,可用作标识符),因此它们仅被定义为一个扩展。



GCC 4.9与<$ c一起使用时$ c> -std = c99 没有定义 M_PI ,但是 -std = gnu99 一起使用时可以做到这一点


I noticed M_PI is unavailable on c11. By looking at /usr/include/math.h I can see M_PI is defined if:

#if !defined(__STRICT_ANSI__) || ((_XOPEN_SOURCE - 0) >= 500)
...
#define M_PI 3.1415...
#endif 

Moreover in the math.h from glibc __STRICT_ANSI__ is replaced with __USE_MISC. I am completely lost with this.

What is the story in between --std=c11 and the constants defined in math.h?

Which libc should I consider on a debian distribution ?

By the way, M_PI is defined in c99 and gnu11...

解决方案

It's simple: M_PI is not defined in standard C. Provide your own definition if you want to be standard-compliant.

C compilers cannot introduce such constants without breaking legal C programs (the name is not reserved, and could be used as an identifier), and as such, they are only defined as an extension.

GCC 4.9 when used with -std=c99 doesn't define M_PI, but does when used with -std=gnu99

这篇关于M_PI不适用于gcc --std = c11,但使用--std = gnu11?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆