2008年12月9日 星期二

On the house

這句片語呢,跟字面上的意思完全無關!!
會提到這句片語,是因為魔獸世界裡面有一個NPC有一句台詞,而台灣的智XD翻譯成

"這是在屋頂上的"

下一句是

"既然是免費的......"

大家應該都覺得上下文完全無關吧...囧rz

第一句的英文原文是 "This is on the house"
而on the house絕對不是在屋頂上......應該是免費的意思!

These drinks are on the house.
這些飲料是免費的。

C/C++ Name mangling

相信常在使用一些C library的人,常常會在標頭檔看到以下的程式碼

#ifdef __cplusplus
extern "C" {
#endif

簡單講,這是為了避免C++的name mangling造成linker無法link到正確的symbol。

C++支援function overloading,所以下列兩個function可以同時存在

void foo(int a);
void foo(double a);

這是因為C++ compiler會將function name"變形",例如:

void func_int(int a);
void func_double(double a);

這樣就沒有衝突的情形了。
但是用C compiler所編譯出來的object,裡面的symbol可是沒有什麼name mangling的
所以linker當然就沒辦法找到C++變形過後的symbol,就出現unresolved symbol的error了
因此,C++提供了extern "C"這個辦法,只要用extern "C"包起來的,compiler就知道裡面的symbol都是"unmangled"的,例如:

extern "C"
{
#include "c_library.h"
}

如此一來,就可以順利link C compiler所編出的object了

另外,各家compiler實做name mangling的方式也不一樣
所以用VC編好的library,沒辦法直接拿去跟gcc的一起link喔,不過這總比因為不相容造成一堆奇怪的問題好多了

參考資料 http://en.wikipedia.org/wiki/Name_mangling

2008年10月17日 星期五

Psalms chapter 90, 10-17

The measure of our life is seventy years; and if through strength it may be eighty years, its pride is only trouble and sorrow, for it comes to an end and we are quickly gone.

Who has knowledge of the power of your wrath, or who takes note of the weight of your passion?

So give us knowledge of the number of our days, that we may get a heart of wisdom.

Come back, O Lord; how long? let your purpose for your servants be changed.

In the morning give us your mercy in full measure; so that we may have joy and delight all our days.

Make us glad in reward for the days of our sorrow, and for the years in which we have seen evil.

Make your work clear to your servants, and your glory to their children.

Let the pleasure of the Lord our God be on us: O Lord, give strength to the work of our hands.

2008年9月24日 星期三

容易緊張

從小就很容易緊張,尤其是月考的那一天,都會緊張的很想大便。
我是不懂心理緊張跟胃腸有什麼關係,但是說不定就是這樣常緊張,才導致我胃腸不好。

長大之後,緊張不會再讓我肚子痛了,但是還是常常"窮緊張"。
明明就是小事,或是根本無法預測會怎樣的事,我還是會心臟跳很快的緊張。
馬太福音六章34節:『不要為明天憂慮,因為明天自有明天的憂慮;一天的難處一天當就夠了。』
人真的是常常想太多的動物,明明就對未來沒有絕對的決定權,想那麼多幹嘛?
舉例來說,有時候今天決定程式要這樣寫,明天老闆一句話就沒有道理的否決你,你又能怎樣?
做好每一天的事就好,讓心臟跳慢一點,也可以活久一點......

2008年9月16日 星期二

頭腦不靈光了

剛剛跟老闆討論事情,腦袋走往錯誤的方向卻完全不知道
還要被人家戳破才知道......真的很糗啊

最近常常這樣呢,遇到要即時思考的情況,都會覺得腦袋很亂
亂轉亂轉找到一個可能的出口之後,就會往那個出口出去,然後思考邏輯就被那個出口合理化了
不知道有沒有人聽的懂,反正就是應該講對的事情,不經思索講成錯的
這種弱點在應徵工作面試的時候,應該會被電得很慘吧Q.Q

2008年8月22日 星期五

小巧可愛的C/C++ library

C/C++不像Java,有齊全的SDK可以用,所以慣用C/C++的人,一定會有一些常用的3rd party libraries
例如XML就會想到libxml,加解密會想到openssl這樣
麻煩的是,這些library都需要先編譯成程式庫才能順利使用
對於常常需要在不同的電腦甚至不同的平台上編譯的程式而言,實在很麻煩
在unix-like的系統上,configure、make、make install三部曲很通用,頂多是花點compilng time
但是在windows上就不是這麼回事了,因為不是每個人都用VC(linux上沒人不用gcc的吧?)
所以library作者可能會用到千奇百怪的build system,光要安裝跟使用這些build system不知道就要多少時間了

以下是一些小巧可愛的library
rapidxml - 只有header file,C++ style
md5 - 很小的C library,就是只算md5而已,不必動用crypto++或是openssl啦
另外就是從其他大的library挖出一小塊想用的來用,例如
apr - Apache Portable Runtime,裡面什麼都有......module的dependency不會太嚴重,還算好拆

2008年8月15日 星期五

Boost 1.36.0 released

http://www.boost.org/users/news/version_1_36_0

好快,跟前一版只差幾個月而已
常用的Thread在1.35.0有個嚴重的bug,雖然馬上被fix了,不過是在1.35.0 release之後
本來想說等1.35.1出來修正這些bug後再來用,沒想到直接跳到1.36.0了= =