標籤:des style c color a int
1、
VS2008:
sizeof cout:56
sizeof cin:60
sizeof streamsize: 4
VS2012
sizeof cout:80
sizeof cin:96
sizeof streamsize: 8
這樣就很明顯了,為了支援大的stream而故意引入streamsize的改變。
2、
以前初學C\C++用pow函數的時候也有點疑惑,為什麼參數int要轉化成double,以為是系統規定的,當時為了編譯能過就用了轉換了,也沒有看原始碼的想法。今天看了HongQian給出的資料才知道,原來是考慮到那麼幾個問題才用double的,而且還提高了複用,感覺設計得很好~(除了給人一點點confuse)
Let‘s count the ways the hypthetical int pow_int(int, int) function could fail.
Overflow
Result undefined pow_int(0,0)
Result can‘t be represented pow_int(2,-1)
The function has at least 2 failure modes. Integers can‘t represent these values, the behaviour of the function in these cases would need to be defined by the standard - and programmers would need to be aware of how exactly the function handles these cases.
3、
花括弧其實是為了定義變數……
加上了花括弧的話,裡面的變數只在這個花括弧裡有用。
case 1:{int a;break;}
case 2:{int a;break;}
否則就得
case 1:int a;break;
case 2:int b;break;
值得注意的是,C85 裡是不允許在任意地方定義變數的,必須放在一個複合陳述式的起始部分。