Navigation Menu

Skip to content

Commit

Permalink
doc coding-style: add about variable declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Apr 9, 2012
1 parent 11fe1f1 commit 9bb3ef6
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions doc/source/developer/coding_style.rst
Expand Up @@ -637,6 +637,32 @@ Cスタイルのキャストはなんでもキャストできてしまうため
char *name;
name = reinterpret_cast<char *>(value);
変数宣言
--------

ポインタ型を示す ``*`` とリファレンス型を示す ``&`` は変数名に寄せる
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Cと同様にポインタ型を示す ``*`` は型名ではなく変数名に寄せる。これは、以下のように複数の変数を一度に宣言したときに一貫性がなくなるためである。2つめ以降の変数は近くに型名がないため ``*`` を寄せる場所がない。

char* key, *value;
同様に、リファレンス型を示す ``&`` も変数名に寄せる。

なお、 ``*`` や ``&`` と型名の間にはスペースを入れない。

よい例:

char *key;
よい例:

bool is_exist(const std::string &file_name);

悪い例(型名に寄せている):

char* key;

その他
------

Expand Down

0 comments on commit 9bb3ef6

Please sign in to comment.