目次: C言語とlibc
C言語のmath.hヘッダには、円周率πを表すマクロM_PIが定義されています。しかしこのマクロ、コンパイラに -std=c99やc11を指定すると使えなくなるんですね。C言語通には常識かもしれませんが、個人的にハマったのでメモしておきます。
#include <math.h>
int main(void)
{
return M_PI;
}
$ gcc -Wall -std=c99 a.c a.c: In function ‘main’: a.c:5:9: error: ‘M_PI’ undeclared (first use in this function) 5 | return M_PI; | ^~~~ a.c:5:9: note: each undeclared identifier is reported only once for each function it appears in
もしc99やc11でもM_PIを使いたい場合は、math.hをインクルードする前に_DEFAULT_SOURCE(_GNU_SOURCEでも良いです)をdefineすると使えるようになります。
#define _DEFAULT_SOURCE
#include <math.h>
int main(void)
{
return M_PI;
}
使えるようになりました。
< | 2021 | > | ||||
<< | < | 09 | > | >> | ||
日 | 月 | 火 | 水 | 木 | 金 | 土 |
- | - | - | 1 | 2 | 3 | 4 |
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | - | - |
合計:
本日:
管理者: Katsuhiro Suzuki(katsuhiro( a t )katsuster.net)
This is Simple Diary 1.0
Copyright(C) Katsuhiro Suzuki 2006-2023.
Powered by PHP 8.2.15.
using GD bundled (2.1.0 compatible)(png support.)