null+****@clear*****
null+****@clear*****
2012年 4月 9日 (月) 16:47:27 JST
Kouhei Sutou 2012-04-09 16:47:27 +0900 (Mon, 09 Apr 2012) New Revision: 9bb3ef6c1c0cf21f43ad7dc071561f29ac9ae6f9 Log: doc coding-style: add about variable declaration Modified files: doc/source/developer/coding_style.rst Modified: doc/source/developer/coding_style.rst (+26 -0) =================================================================== --- doc/source/developer/coding_style.rst 2012-04-09 16:21:57 +0900 (ab244b8) +++ doc/source/developer/coding_style.rst 2012-04-09 16:47:27 +0900 (cd61f1e) @@ -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; + その他 ------