M_PI not available with gcc --std=c11 but with --std=gnu11?

前端 未结 3 1926
悲&欢浪女
悲&欢浪女 2020-12-15 09:55

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

#i         


        
3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-15 10:06

    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

提交回复
热议问题