1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

define文で式の値がおかしいときにチェックすべきこと1選

Last updated at Posted at 2024-11-06

define文に式を書くなら括弧で囲め!!

define文は計算結果を格納しているのではなく、文字として置き換えるだけ!

#define HOGE 100 / 20
#define FUGA HOGE / HOGE

とした場合、FUGAは$ 5 / 5 = 1$ではなく$100 / 20 / 100 / 20 = 0.0025$になる。
FUGAを1にしたいなら

#define HOGE (100 / 20)
#define FUGA (HOGE / HOGE)

にしよう!
FUGAを使ったdefineがおかしくなるのも防ぐためにFUGAにも、すべてに括弧をつけよう!
悪いことは言わない。俺みたいになるな!!!!

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?