5
4

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 5 years have passed since last update.

テンポラリデータポインタの扱い

Last updated at Posted at 2013-12-24

テンポラリデータのポインタを引数にするときは下みたいにconstにしてやらないと「taking address of temporary array」と言われてしまう。テンポラリデータじゃ戻ってからのアクセス手段がないので値を書き込んでも使えないからね。しかし、コンストラクタのメンバを初期化するところでテンポラリデータのポインタを食わせると...

magMax((const double[]){ MAXFLOAT, MAXFLOAT, MAXFLOAT }), //OK

これは通る。が、

magMax((const double[]){ -MAXFLOAT, MAXFLOAT, MAXFLOAT }), //NG

これは「taking address of temporary array」で通らない。違いは単項の「-」だけ。しかし、

magMax((const double[]){ 0-MAXFLOAT, MAXFLOAT, MAXFLOAT }), //OK

と単項ではない「-」だと通る。上のコードは3つともconstなテンポラリデータのポインタを食わせているのに。
...わけがわからないよ。

とは言え、MAXFLOATはstatic const floatなのでその辺が関係あるのかもしれないし、C++の推奨に反してマクロで与えてやるとまた違った結果になる可能性がある。

5
4
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
5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?