Porting

也許移植一個 .Net application 到其他平台上,並不如想像中容易。
正如 Java application 並不是 100% 的 run anywhere。
Mono專案的頭頭最近把Paint.NET移植到 Linux 的Mono上,你可以看看這篇他的文章:Porting Paint.NET to Mono
看到這個標題,我是很高興的,可是看完以後,發現移植的過程曲折離奇,其中的過程頗值得玩味。

new之後,constructor之前

昨天在代碼裡面看到一個從沒看過的用法,如下列紅色標示部份:

#include <iostream>

class MyBase {
  protected:
    int _id;

  public:
    MyBase():_id(0) {}
    MyBase( int id ):_id(id) {}
    int getId() {return _id; }
};

class MyClass: public MyBase {
  public:
    MyClass() {}
    MyClass( int id ):MyBase( id ) {}
};

int myclass_mem[ sizeof(MyClass)/sizeof(int) ];

using namespace std;

MyBase* test()
{
  return new (myclass_mem)MyClass( 100 );// 這裡 (1)
  //return new MyClass( 100 ); // (2)
}

int
main( int argc, char* argv[] )
{
  int len = sizeof( myclass_mem );
  cout << "The size of myclass_mem is " << len << endl;
  cout << "content of myclass_mem" << endl;
  for( int i=0; i<len; i++ )
    cout << myclass_mem[i] << ” “;
  cout << endl;

  MyBase* base = ::test();
  cout << base->getId() << endl;

  cout << "content of myclass_mem" << endl;
  for( int i=0; i<len; i++ )
    cout << myclass_mem[i] << ” “;
  cout << endl;
}

以執行的結果來說,我實在是分辨不出來 (1) 與 (2) 有甚麼分別。
後來我用 gcc -S 去分別產生組合語言碼,總算是大致猜到了,原來以 (1) 的方法來寫,會把 new 以後的結果也複製到 myclass_mem 這個陣列裡面。
所以加上輸出 myclass_mem 內容的程式碼,再分別產生執行檔來看執行結果就很清楚了。
真是特別。

好人卡

沒事去參加團購,買了這個,準備當作禮物送人…
誰會是第一個好人?
好人卡拆箱照(1)
好人卡拆箱照(2)
好人卡拆箱照(3)

taglist的安裝與使用

自從使用 ctags 以後,看code方便多了。最近又看到taglist,心想或許可以讓看code的生活變得更美好,所以就來摸索看看。
首先到這裡下載最新版本。
解開以後,有兩個目錄,一個是 doc,另外一個是 plugin,把他們複製到你的 HOME 的 vimfiles 目錄下(舉例:c:\documents and settings\your_name\vimfiles\),然後在你的 _vimrc 裡面指定 Tlist_Ctags_Cmd 變數,這是用來讓 taglist 知道 ctags 的路徑。
我是把 ctags.exe 放在 c:\tools 下,所以是這樣寫:

let Tlist_Ctags_Cmd=’c:\tools\ctags.exe’

這樣就大功告成了。
使用的時候,

  • 用 :TlistOpen 指令把 taglist 視窗叫出來,用 :TlistClose 指令關閉 taglist 視窗
  • 用 :TListToggle 來打開或關閉 taglist 視窗
  • 可以用 ctrl-w h 與 ctrl-w l 來切換 taglist 視窗與編輯視窗
  • 開啟檔案以後,taglist會自動把 tag 資訊列在左邊視窗。


備註:
我沒在 Linux 下用過,安裝方法應該差不多;記得把 HOME 替換為 /home,vimfiles/ 替換為 .vim/。
Console 模式下,有比較特別,文件說,因為 terminal/console 不支援變動視窗寬度,所以要設置 Tlist_Inc_Winwidth 為 0。