[問題] 谷歌的C++ Style Guide
看板C_and_CPP (C/C++)作者rosemary0401 (rosemary)時間13年前 (2012/11/18 17:29)推噓0(0推 0噓 10→)留言10則, 4人參與討論串1/2 (看更多)
最近在study谷歌的C++ Style Guide
http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml
有一些看不太懂的地方:
===== Q1 =====
The -inl.h Files:
...However, implementation code properly belongs in .cc files, and we do not
like to have much actual code in .h files unless there is a readability or
performance advantage...
有聽過類似的建議,不要再header file裡面放太多實作,
實作盡量放在.c file裡,但是不太知道這樣做的好處是什麼???
谷歌的style guide又提到"unless there is a readability or performance advantage"
但在甚麼樣的情況下,把實作的code搬到header file會提升performance呢???
===== Q2 =====
Casting:
Use C++ casts like static_cast<>(). Do not use other cast formats like
int y = (int)x; or int y = int(x);.
Pros:
The problem with C casts is the ambiguity of the operation; sometimes you are
doing a conversion (e.g., (int)3.5) and sometimes you are doing a cast (e.g.,
(int)"hello"); C++ casts avoid this. Additionally C++ casts are more visible
when searching for them.
看不太懂C style的轉型不好的點在哪??
意思是說C style的轉型太暴力,
連不合乎邏輯的轉型都可以轉的過嗎??? (比方說: (int)"hello")
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 122.116.153.199
※ 編輯: rosemary0401 來自: 122.116.153.199 (11/18 17:30)
→
11/18 17:37, , 1F
11/18 17:37, 1F
→
11/18 17:38, , 2F
11/18 17:38, 2F
→
11/18 17:41, , 3F
11/18 17:41, 3F
→
11/18 17:45, , 4F
11/18 17:45, 4F
→
11/18 17:46, , 5F
11/18 17:46, 5F
→
11/18 17:48, , 6F
11/18 17:48, 6F
→
11/18 21:24, , 7F
11/18 21:24, 7F
→
11/18 21:25, , 8F
11/18 21:25, 8F
→
11/18 23:50, , 9F
11/18 23:50, 9F
→
11/19 06:19, , 10F
11/19 06:19, 10F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 2 篇):
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章