arduino / arduino/ArduinoCore-API
Use of macros for math functions causes unexpected results when argument has side effect
- 主要言語
- C++
- スター
- 306
- フォーク
- 150
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
I find semantically wrong the fact that the following math functions are implemented as macros:
- `abs`
- `constrain`
- `round`
- ~~`min`~~
- ~~`max`~~
... and let me add `bitWrite` to the list.
It is well known that using these function the way the rest of the world does introduces faults, and therefore generates failures.
Writing something like `abs(cos(x) - 123 * sq(sin(x))` would introduce **redundant calculations**, just a crazy delay in this case...
Writing something like `abs(a += b)` or `abs(i++)` just introduces a **fault**... it does something different (wrong in fact).
I assume that using **template** and **inline** functions would solve the issue with no extra executable space taken.
### Additional context
#### Additional reports
- https://github.com/arduino/Arduino/issues/9571
- https://github.com/arduino/ArduinoCore-avr/issues/324
#### Related
- https://github.com/arduino/reference-en/pull/513
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
調査の方向性
まず abs、constrain、round、bitWrite に対応する Arduino API の定義を見つけ、次に関連する報告を調べて、期待される動作と互換性に関する懸念を確認します。問題のあるマクロの動作を提案されている関数アプローチに置き換え、副作用のある引数が API を変更せずに一度だけ評価されることを検証します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- cpp
- 領域
- api, embedded-iot
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100