使用M_PI与C89标准 [英] Using M_PI with C89 standard

查看:377
本文介绍了使用M_PI与C89标准的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用C和试图访问的常量M_PI(3.14159 ...)。我已经导入文件math.h头文件,但M_PI常量仍然不确定。通过在计算器上一番搜索,我发现我需要的#define _USE_MATH_DEFINES 添加到我的code(见例如code以下)。通常编译时,此工作正常,但我需要能够与 STD = C89 标志,我做的工作进行编译。

I'm using C and trying to get access to the constant M_PI (3.14159...). I have imported the math.h header file, but the M_PI constant was still undefined. Through some searching on StackOverflow I have found that I need to add #define _USE_MATH_DEFINES to my code (see example code below). This works fine when compiling normally, but I need to be able to compile with the std=c89 flag for the work that I'm doing.

我应该如何从一些C89 code访问M_PI?

How should I access M_PI from some C89 code?

推荐答案

一个符合标准的库文件文件math.h 不仅没有要求,但实际上的千万不要确定 M_PI 默认情况下。在此背景下'默认'的意思是 M_PI 只能获得通过具体的编译器技巧定义,通过使用保留的标识符的最常见未定义的行为。

A conforming standard library file math.h is not only not required to, but actually must not define M_PI by default. In this context 'by default' means that M_PI must only get defined through compiler-specific tricks, most often undefined behavior through the use of reserved identifiers.

只要定义常量自己(你可以使用名称 M_PI 自由,但你应该希望能够编译code有不符合要求的编译器,您必须首先检查 M_PI 尚未定义)。对于约定的缘故,不要定义 M_PI 作为比PI(的近似值)的任何其他。

Just define the constant yourself (you can use the name M_PI freely, but should you want to be able to compile the code with a non-conforming compiler, you must first check that M_PI is not already defined). For convention's sake, do not define M_PI as anything other than (the approximation of) pi.

这篇关于使用M_PI与C89标准的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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