C++初期設計者が書いた `int* p` と `int *p` に関する文章
(stroustrup.com)int *pは、*pの型がintであるという論理である。int* pは、pの型がpointer of intであるという論理である。- 1行で複数の変数を宣言するとき、
int *pのほうが誤解の余地が少ない。int *p0, p1; // p0 :: int*, p1 :: intint* p0, p1; // p0 :: int*, p1 :: int (int* だと勘違いしやすい)
- 1行で複数の変数を宣言しなければ、この問題は発生しない。
- C++の初期設計者自身は、どちらも正しいと考えているが、
int* pをより好んでいる。
3件のコメント
やはりコーディングは文学です
int *pと書き、*pの型がintだと説明するint* pと書き、pの型がpointer of intだと説明する"Whenever something is a matter of taste, discussions can drag on forever."
余談ですが、
int *p形式を使っています。