<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss'><id>tag:blogger.com,1999:blog-3602674777707139629</id><updated>2009-12-24T19:02:20.934+08:00</updated><title type='text'>lui</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://kc-lui.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3602674777707139629/posts/default'/><link rel='alternate' type='text/html' href='http://kc-lui.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/3602674777707139629/posts/default?start-index=26&amp;max-results=25'/><author><name>lui</name><uri>http://www.blogger.com/profile/08679538620572861199</uri><email>noreply@blogger.com</email></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>50</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-3602674777707139629.post-1970355352455579538</id><published>2009-12-11T13:47:00.047+08:00</published><updated>2009-12-15T02:50:35.390+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C/C++'/><title type='text'>Invoke pure virtual function</title><content type='html'>沒錯　你沒看錯&lt;br/&gt;
這篇的標題是呼叫純虛擬函式&lt;br/&gt;
一個沒有實作的純虛擬函式是有可能被呼叫起來的&lt;br/&gt;
&lt;pre class="cpp" name="code"&gt;
class A {
public:
    virtual void f(void) = 0;
};
class B : public A {
    virtual void f(void) {}
};
&lt;/pre&gt;
在系統開發中　這是一個很常出現的程式片斷&lt;br/&gt;
在多型體系中&lt;br/&gt;
A* a = new B;&lt;br/&gt;
a-&gt;f();&lt;br/&gt;
因為vtable的存在　程式會為f找尋合適的function pointer並呼叫&lt;br/&gt;
這例子中從vtable中會找到class B中的f()&lt;br/&gt;
這並沒有甚麼問題&lt;br/&gt;
那麼如果vtable中沒有class B的資訊時會怎麼樣　那就會找到class A的f()&lt;br/&gt;
就會呼叫純虛擬函式了&lt;br/&gt;
&lt;br/&gt;
這會發生嗎？&lt;br/&gt;
會的&lt;br/&gt;
&lt;pre class="cpp" name="code"&gt;
class A;
class A {
public:
    virtual ~A() { m_pA-&gt;Close(); }
    virtual void Close(void) = 0;
    A* m_pA;
};
class B : public A {
    virtual void Close(void) {}
};
&lt;/pre&gt;
像這樣的程式&lt;br/&gt;
一般人會想說把所有的CloseXXX, DeleteXXX, DestoryXXX寫在解構子&lt;br/&gt;
解構子被呼叫的順序是從下而上&lt;br/&gt;
所以B的解構子先呼叫　把vtable清掉&lt;br/&gt;
A的解構子再呼叫　這時vtable中只有class A　所以就呼叫一個純虛擬函式了&lt;br/&gt;
&lt;br/&gt;
當然　Effective C++裡提到　不應該在解構子呼叫虛擬函式　會有類似的問題出現&lt;br/&gt;
而在多執行緒中　也可能發生&lt;br/&gt;
&lt;pre class="cpp" name="code"&gt;
class B : public A {
    virtual void f(void) {}
    void ThreadProc() {
        while(1)
            f();
    }
};

void main() {
    A* a = new B();

    while(1) {
        if (...)
            a-&gt;Create();
        if (exception == true)
            break;
    }
    delete a;
}
&lt;/pre&gt;
我們把class B改為一個thread　它會不斷的呼叫f()&lt;br/&gt;
當一個執行緒因為例外發生或其他原因　使物件的解構子被呼叫&lt;br/&gt;
呼叫到一半的時候　另一個執行緒呼叫該物件的虛擬函式&lt;br/&gt;
剛好解構到vtable只剩下Base class時　就會呼叫純虛擬函式了&lt;br/&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3602674777707139629-1970355352455579538?l=kc-lui.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kc-lui.blogspot.com/feeds/1970355352455579538/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3602674777707139629&amp;postID=1970355352455579538' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3602674777707139629/posts/default/1970355352455579538'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3602674777707139629/posts/default/1970355352455579538'/><link rel='alternate' type='text/html' href='http://kc-lui.blogspot.com/2009/12/invoke-pure-virtual-function.html' title='Invoke pure virtual function'/><author><name>lui</name><uri>http://www.blogger.com/profile/08679538620572861199</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09005455948053450369'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3602674777707139629.post-8802539224717637577</id><published>2009-11-19T21:06:00.005+08:00</published><updated>2009-12-15T02:51:33.746+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='music'/><title type='text'>說謊</title><content type='html'>主唱：林宥嘉&lt;br/&gt;
詞：施人誠&lt;br/&gt;
曲：李雙飛&lt;br/&gt;
&lt;br/&gt;
是有過幾個不錯對象 說起來並不寂寞孤單&lt;br/&gt;
可能我浪蕩 讓人家不安&lt;br/&gt;
才會 結果都陣亡&lt;br/&gt;
&lt;br/&gt;
我沒有什麼陰影魔障 妳千萬不要放在心上&lt;br/&gt;
我又不脆弱 何況那算什麼傷&lt;br/&gt;
反正愛情不就都這樣&lt;br/&gt;
&lt;br/&gt;
我沒有說謊 我何必說謊&lt;br/&gt;
妳懂我的 我對妳從來就不會假裝&lt;br/&gt;
我哪有說謊&lt;br/&gt;
請別以為妳有多難忘 笑是真的不是我逞強&lt;br/&gt;
&lt;br/&gt;
我好久沒來這間餐廳 沒想到已經換了裝潢&lt;br/&gt;
角落那窗口 聞得到玫瑰花香&lt;br/&gt;
被妳一說是有些印象&lt;br/&gt;
&lt;br/&gt;
我沒有說謊 我何必說謊&lt;br/&gt;
妳知道的 我缺點之一就是很健忘&lt;br/&gt;
我哪有說謊&lt;br/&gt;
是很感謝今晚的相伴 但我竟然有些不習慣&lt;br/&gt;
&lt;br/&gt;
我沒有說謊 我何必說謊&lt;br/&gt;
愛一個人 沒愛到難道就會怎麼樣&lt;br/&gt;
別說我說謊&lt;br/&gt;
人生已經如此的艱難 有些事情就不要拆穿&lt;br/&gt;
&lt;br/&gt;
我沒有說謊 是愛情說謊&lt;br/&gt;
它帶妳來 騙我說 渴望的有可能有希望&lt;br/&gt;
我沒有說謊&lt;br/&gt;
祝妳做個幸福的新娘 我的心事請妳就遺忘&lt;br/&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3602674777707139629-8802539224717637577?l=kc-lui.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kc-lui.blogspot.com/feeds/8802539224717637577/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3602674777707139629&amp;postID=8802539224717637577' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3602674777707139629/posts/default/8802539224717637577'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3602674777707139629/posts/default/8802539224717637577'/><link rel='alternate' type='text/html' href='http://kc-lui.blogspot.com/2009/11/blog-post.html' title='說謊'/><author><name>lui</name><uri>http://www.blogger.com/profile/08679538620572861199</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09005455948053450369'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3602674777707139629.post-8668013136681063507</id><published>2009-07-28T00:56:00.004+08:00</published><updated>2009-12-15T02:52:08.447+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C/C++'/><title type='text'>C/C++ with MySQL</title><content type='html'>最近一直找一個bug  找很久都找不出來&lt;br/&gt;
&lt;br/&gt;
狀況是這樣子&lt;br/&gt;
&lt;br/&gt;
在一台linux上裝上 MySQL 5.0, Apache 2.0, django 1.0, openssl 5.5.2&lt;br/&gt;
&lt;br/&gt;
建立一台有網頁  有cgi  有ssl的平台&lt;br/&gt;
&lt;br/&gt;
之後複製另一台成master and slave  同時使用 MySQL Replication&lt;br/&gt;
&lt;br/&gt;
令兩台資料庫保持一致狀態  作為master掛掉時自動起來的back up server&lt;br/&gt;
&lt;br/&gt;
問題來了  它們總是不一致&lt;br/&gt;
&lt;br/&gt;
測了很久發現我c++的cgi使用Connector/C++ 1.0 Preview來連接MySQL  但不會產生MySQL的binary log&lt;br/&gt;
&lt;br/&gt;
沒有binary log就沒辨法使用MySQL Replication&lt;br/&gt;
&lt;br/&gt;
後來&lt;br/&gt;
&lt;br/&gt;
花了個晚上把Connector/C++換成MySQL++&lt;br/&gt;
&lt;br/&gt;
&lt;br/&gt;
看來兩套功能相同的東西  還是選版本比較大的好  = ="&lt;br/&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3602674777707139629-8668013136681063507?l=kc-lui.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kc-lui.blogspot.com/feeds/8668013136681063507/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3602674777707139629&amp;postID=8668013136681063507' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3602674777707139629/posts/default/8668013136681063507'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3602674777707139629/posts/default/8668013136681063507'/><link rel='alternate' type='text/html' href='http://kc-lui.blogspot.com/2009/07/cc-with-mysql.html' title='C/C++ with MySQL'/><author><name>lui</name><uri>http://www.blogger.com/profile/08679538620572861199</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09005455948053450369'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3602674777707139629.post-8992015832794472743</id><published>2009-07-27T01:36:00.009+08:00</published><updated>2009-12-15T02:52:22.426+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='life'/><title type='text'>摸索</title><content type='html'>半年來&lt;br/&gt;
每天不斷的上班　上班　除了上班還剩甚麼&lt;br/&gt;
每天趨於平淡　盲目&lt;br/&gt;
我想要的生命似乎漸漸地從手中流失&lt;br/&gt;
就這樣嗎?&lt;br/&gt;
我的生活需要點不一樣的　需要點衝擊&lt;br/&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3602674777707139629-8992015832794472743?l=kc-lui.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kc-lui.blogspot.com/feeds/8992015832794472743/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3602674777707139629&amp;postID=8992015832794472743' title='5 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3602674777707139629/posts/default/8992015832794472743'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3602674777707139629/posts/default/8992015832794472743'/><link rel='alternate' type='text/html' href='http://kc-lui.blogspot.com/2009/07/blog-post.html' title='摸索'/><author><name>lui</name><uri>http://www.blogger.com/profile/08679538620572861199</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09005455948053450369'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3602674777707139629.post-9182229431249058545</id><published>2009-07-25T23:41:00.007+08:00</published><updated>2009-12-15T02:58:01.520+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='music'/><title type='text'>The Show</title><content type='html'>&lt;a href="http://www.youtube.com/watch?v=hnN30rs5NkQ" style="text-decoration: none;"&gt;http://www.youtube.com/watch?v=hnN30rs5NkQ&lt;/a&gt;&lt;br/&gt;十分值得聽的歌  澳洲的創作女歌生 lenka&lt;br/&gt;
The Show&lt;br/&gt;
&lt;br/&gt;
I'm just a little bit&lt;br/&gt;
caught in the middle&lt;br/&gt;
Life is a maze&lt;br/&gt;
and love is a riddle&lt;br/&gt;
I don't know where to go&lt;br/&gt;
I can't do it alone&lt;br/&gt;
(I've tried)&lt;br/&gt;
and I don't know why&lt;br/&gt;
its cuz jollys cool&lt;br/&gt;
&lt;br/&gt;
Slow it down&lt;br/&gt;
make it stop&lt;br/&gt;
or else my heart is going to pop&lt;br/&gt;
'cuz it's too much&lt;br/&gt;
Yeah, it's a lot&lt;br/&gt;
to be something I'm not&lt;br/&gt;
&lt;br/&gt;
I'm a fool&lt;br/&gt;
out of love&lt;br/&gt;
'cuz I just can't get enough&lt;br/&gt;
&lt;br/&gt;
I'm just a little bit&lt;br/&gt;
caught in the middle&lt;br/&gt;
Life is a maze&lt;br/&gt;
and love is a riddle&lt;br/&gt;
I don't know where to go&lt;br/&gt;
I can't do it alone&lt;br/&gt;
(I've tried)&lt;br/&gt;
and I don't know why&lt;br/&gt;
&lt;br/&gt;
I am just a little girl&lt;br/&gt;
lost in the moment&lt;br/&gt;
I'm so scared&lt;br/&gt;
but I don't show it&lt;br/&gt;
I can't figure it out&lt;br/&gt;
it's bringing me down&lt;br/&gt;
I know&lt;br/&gt;
I've got to let it go&lt;br/&gt;
and just enjoy the show&lt;br/&gt;
&lt;br/&gt;
The sun is hot&lt;br/&gt;
in the sky&lt;br/&gt;
just like a giant spotlight&lt;br/&gt;
The people follow the sign&lt;br/&gt;
and synchronize in time&lt;br/&gt;
It's a joke&lt;br/&gt;
Nobody knows&lt;br/&gt;
they've got a ticket to that show&lt;br/&gt;
Yeah&lt;br/&gt;
&lt;br/&gt;
I'm just a little bit&lt;br/&gt;
caught in the middle&lt;br/&gt;
Life is a maze&lt;br/&gt;
and love is a riddle&lt;br/&gt;
I dont know where to go&lt;br/&gt;
I can't do it alone&lt;br/&gt;
(I've tried)&lt;br/&gt;
and I don't know why&lt;br/&gt;
&lt;br/&gt;
I am just a little girl&lt;br/&gt;
lost in the moment&lt;br/&gt;
I'm so scared&lt;br/&gt;
but don't show it&lt;br/&gt;
I can't figure it out&lt;br/&gt;
it's bringing me down&lt;br/&gt;
I know&lt;br/&gt;
I've got to let it go&lt;br/&gt;
and just enjoy the show&lt;br/&gt;
&lt;br/&gt;
oh oh&lt;br/&gt;
Just enjoy the show&lt;br/&gt;
oh oh&lt;br/&gt;
&lt;br/&gt;
I'm just a little bit&lt;br/&gt;
caught in the middle&lt;br/&gt;
life is a maze&lt;br/&gt;
and love is a riddle&lt;br/&gt;
I dont know where to go&lt;br/&gt;
I can't do it alone&lt;br/&gt;
(I've tried)&lt;br/&gt;
and I don't know why&lt;br/&gt;
&lt;br/&gt;
I am just a little girl&lt;br/&gt;
lost in the moment&lt;br/&gt;
I'm so scared&lt;br/&gt;
but I don't show it&lt;br/&gt;
I can't figure it out&lt;br/&gt;
it's bringing me down&lt;br/&gt;
I know&lt;br/&gt;
I've got to let it go&lt;br/&gt;
and just enjoy the show&lt;br/&gt;
&lt;br/&gt;
dum de dum&lt;br/&gt;
dudum de dum&lt;br/&gt;
&lt;br/&gt;
Just enjoy the show&lt;br/&gt;
&lt;br/&gt;
dum de dum&lt;br/&gt;
dudum de dum&lt;br/&gt;
&lt;br/&gt;
Just enjoy the show&lt;br/&gt;
&lt;br/&gt;
I want my money back&lt;br/&gt;
I want my money back&lt;br/&gt;
I want my money back&lt;br/&gt;
Just enjoy the show&lt;br/&gt;
&lt;br/&gt;
I want my money back&lt;br/&gt;
I want my money back&lt;br/&gt;
I want my money back&lt;br/&gt;
Just enjoy the show&lt;br/&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3602674777707139629-9182229431249058545?l=kc-lui.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kc-lui.blogspot.com/feeds/9182229431249058545/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3602674777707139629&amp;postID=9182229431249058545' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3602674777707139629/posts/default/9182229431249058545'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3602674777707139629/posts/default/9182229431249058545'/><link rel='alternate' type='text/html' href='http://kc-lui.blogspot.com/2009/07/show.html' title='The Show'/><author><name>lui</name><uri>http://www.blogger.com/profile/08679538620572861199</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09005455948053450369'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3602674777707139629.post-8268493564310197199</id><published>2008-12-09T13:43:00.003+08:00</published><updated>2009-12-15T02:59:44.556+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='music'/><title type='text'>you and i both</title><content type='html'>歌名:you and i both&lt;br/&gt;
演唱:jason mraz&lt;br/&gt;
&lt;br/&gt;
Was it you who spoke the words that things would happen but not to me?&lt;br/&gt;
All things are gonna happen naturally&lt;br/&gt;
Oh, taking your advice and I'm looking on the bright side&lt;br/&gt;
And balancing the whole thing.&lt;br/&gt;
&lt;br/&gt;
Oh, but at often times those words get tangled up in a lines&lt;br/&gt;
And the bright light turns to night&lt;br/&gt;
Oh, until the dawn it brings&lt;br/&gt;
Another day to sing about the magic that was you and me&lt;br/&gt;
&lt;br/&gt;
Cause you and I both loved&lt;br/&gt;
What you and I spoke of&lt;br/&gt;
And others just read of&lt;br/&gt;
Others only read of, of the love&lt;br/&gt;
Of the love that I loved&lt;br/&gt;
&lt;br/&gt;
lova lova!&lt;br/&gt;
&lt;br/&gt;
See I'm all about them words&lt;br/&gt;
Over numbers, unencumbered numbered words;&lt;br/&gt;
Hundreds of pages, pages, pages for words.&lt;br/&gt;
More words than I had ever heard, and I feel so alive.&lt;br/&gt;
&lt;br/&gt;
Cause you and I both loved&lt;br/&gt;
What you and I spoke of&lt;br/&gt;
And others just read of&lt;br/&gt;
And if you could see me now&lt;br/&gt;
Oh, love love&lt;br/&gt;
You and I, You and I&lt;br/&gt;
Not so little you and I anymore&lt;br/&gt;
&lt;br/&gt;
And with this silence brings a moral story&lt;br/&gt;
More importantly evolving is the glory of a boy&lt;br/&gt;
&lt;br/&gt;
Cause you and I both loved&lt;br/&gt;
What you and I spoke of (of, of)&lt;br/&gt;
And others just read of&lt;br/&gt;
And if you could see me now&lt;br/&gt;
Well, then I'm almost finally out of&lt;br/&gt;
I'm finally out of&lt;br/&gt;
Finally deedeedeedeedeedee&lt;br/&gt;
Well I'm almost finally, finally&lt;br/&gt;
Well I am free&lt;br/&gt;
Oh, I'm free&lt;br/&gt;
&lt;br/&gt;
And it's okay if you had to go away&lt;br/&gt;
Oh, just remember that telephones&lt;br/&gt;
Well, they work out of both ways&lt;br/&gt;
But if I never ever hear them ring&lt;br/&gt;
If nothing else I'll think the bells inside&lt;br/&gt;
Have finally found you someone else and that's okay&lt;br/&gt;
Cause I'll remember everything you sang&lt;br/&gt;
&lt;br/&gt;
Cause you and I both loved&lt;br/&gt;
What you and I spoke of (of,)&lt;br/&gt;
And others just read of&lt;br/&gt;
and if you could see me now&lt;br/&gt;
Well, then I'm almost finally out of&lt;br/&gt;
I'm finally out of&lt;br/&gt;
Finally deedeedeedeedeede&lt;br/&gt;
Well I'm almost finally, finally&lt;br/&gt;
Out of words&lt;br/&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3602674777707139629-8268493564310197199?l=kc-lui.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kc-lui.blogspot.com/feeds/8268493564310197199/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3602674777707139629&amp;postID=8268493564310197199' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3602674777707139629/posts/default/8268493564310197199'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3602674777707139629/posts/default/8268493564310197199'/><link rel='alternate' type='text/html' href='http://kc-lui.blogspot.com/2008/12/you-and-i-both.html' title='you and i both'/><author><name>lui</name><uri>http://www.blogger.com/profile/08679538620572861199</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09005455948053450369'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3602674777707139629.post-8389252723262904361</id><published>2008-11-15T15:58:00.015+08:00</published><updated>2009-12-15T03:30:29.746+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><category scheme='http://www.blogger.com/atom/ns#' term='ubuntu'/><title type='text'>Apache+MySQL+PHP+OpenSSL in Ubuntu</title><content type='html'>&lt;span style="font-weight: bold;font-size:130%;" &gt;SSL介紹&lt;/span&gt;
SSL(Secure Socket Layer)是Netscape所提出來的資料保密協定，採用了RC4、MD5，以及RSA等加密演算法。&lt;br/&gt;
&lt;br/&gt;
網路上需要確定網站真的是那個網站，所以SSL也具備認證的機能。SSL是以金字塔的結構
組成，最下層的是一般的伺服器，它們經由向上跟CA申請取得SSL的憑證，CA會在SSL相關檔案上簽名，CA是具有公信力和認證能力的機構，CA必須向上跟RootCA(如政府機構等)申請。當使用者連結具SSL的服務時，伺服器會傳送憑證給使用者，使用端的程式接收到憑證後會向CA確認憑證，若CA確認這個憑是它們簽發的則會回傳給使用端正確的訊息。
具有SSL功能的網站可以向 世界少數幾個發證機構（例如目前最大的VeriSign或第二大的Thawte兩家認證公司）申請，經過嚴格的文件證明確認後，才能取得國際認可（較新版 的MSIE或Netscape瀏覽軟體會自動認得）的電子認證。&lt;br/&gt;
&lt;br/&gt;
  所有 SSL憑證都是發給公司或是法人，典型的 SSL 憑證將包括您的網域名稱(domain                  name)、您的公司名稱(company                  name)、您的住址(address)、您的所在城市(city)、您的省份(state)和您的國家(country)，它也包含了憑證的到期日和負責核發此憑證的發證中心詳細資料。當一個瀏覽器連結到一個安全網站時，它將收到這個網站的SSL憑證並且檢驗它是否過期、它是否是已經被瀏覽器信任的發證中心所核發的，以及它是否如核發時 所登記的內容被該網站使用，假如有任何一項檢查不通過，瀏覽器將顯示一個警告訊息給使用者。&lt;br/&gt;
&lt;br/&gt;
&lt;span style="font-weight: bold;font-size:130%;" &gt;在Ubuntu上安裝 apache+mysql+php+openssl&lt;/span&gt;
&lt;pre class="bash" name="code"&gt;
sudo tasksel install lamp-server
安裝 lamp (apache mysql php)

sudo apt-get install mysql-admin mysql-gui-tools-common mysql-query-browser
安裝mysql的管理介面

sudo apt-get install -y php5-gd
安裝GD庫

sudo apt-get install -y openssl
安裝Openssl

sudo apt-get install -y ssl-cert
安裝簽署憑證的工具

sudo a2enmod ssl
安裝ssl模組

sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/ssl
sudo ln -s /etc/apache2/sites-available/ssl /etc/apache2/sites-enabled/ssl
複製一份預設擋供ssl用，並且用ln建立連結（捷徑）至sites-enabled/ssl

sudo vim /etc/apache2/sites-enabled/ssl
在以下位置後面加入紅色的設定值

NameVirtualHost *:443


sudo vim /etc/apache2/sites-enabled/default
在以下位置後面加入紅色的設定值

NameVirtualHost *:80
SSLEngine On
SSLCerficationFile /etc/apache2/etc/apache.pem


sudo vim /usr/sbin/make-ssl-cert
將"-keyout $output"改成"-keyout $output -days 3650"即可將憑證有效時間改成10年

sudo mkdir /etc/apache2/ssl
建立ssl憑證所擺放目錄

sudo make-ssl-cert /usr/share/ssl-cert/ssleay.cnf /etc/apache2/etc/apache.pem
make-ssl-cert is a wrapper of OpenSSL
依照指示輸入憑證相關訊息，即可產生自簽的電子證書！

sudo /etc/init.d/apache2 force-reload
重新載入配置

sudo /etc/init.d/apache2 restart
重新啟動Apache2
&lt;/pre&gt;
&lt;span style="font-weight: bold;font-size:130%;" &gt;產生自簽的CA&lt;/span&gt;
產生自簽的CA的意義是，自己架設一個CA，並為自己的伺服器的憑證簽名。則使用端收到憑證時，會向CA確定，這時就用自己架的CA去確認說憑證是有效的。當然這樣是沒有公信力的，而且把自己架的伺服器登記為CA需要手動加入，一般這樣做都是為了測試用。&lt;br/&gt;
&lt;br/&gt;
參考以下連結&lt;br/&gt;
&lt;a href="http://wiki.ubuntu.org.cn/OpenSSL"&gt;http://wiki.ubuntu.org.cn/OpenSSL&lt;/a&gt;
主要做兩件事情&lt;br/&gt;
第一件是架CA：Creating the Certificate Authority&lt;br/&gt;
第二件是架server：Creating a Self-Signed Server Certificate&lt;br/&gt;
並使用自己的CA為它簽名&lt;br/&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3602674777707139629-8389252723262904361?l=kc-lui.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kc-lui.blogspot.com/feeds/8389252723262904361/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3602674777707139629&amp;postID=8389252723262904361' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3602674777707139629/posts/default/8389252723262904361'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3602674777707139629/posts/default/8389252723262904361'/><link rel='alternate' type='text/html' href='http://kc-lui.blogspot.com/2008/11/apachemysqlphpopenssl.html' title='Apache+MySQL+PHP+OpenSSL in Ubuntu'/><author><name>lui</name><uri>http://www.blogger.com/profile/08679538620572861199</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09005455948053450369'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3602674777707139629.post-7283356867570110406</id><published>2008-11-09T23:53:00.009+08:00</published><updated>2009-12-15T02:58:38.252+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>Reverse Engineering Tools</title><content type='html'>&lt;h3&gt;Microsoft Windows&lt;/h3&gt;Three tools pervade the warchest of the contemporary analyst on the Windows platform: &lt;a href="http://www.datarescue.com/" target="_blank"&gt;IDA&lt;/a&gt;, SoftICE, and &lt;a href="http://freewareapp.com/pe-tools_download/" target="_blank"&gt;PE Tools&lt;/a&gt;. IDA is the Interactive Disassembler from Data Rescue. IDA is used to examine the executable on-disk. IDA provides useful features such as call graphs for analyzing program flow and automatic library detection.&lt;br/&gt;
&lt;br/&gt;
SoftICE is a &lt;a href="http://en.wikipedia.org/wiki/Ring_%28computer_security%29" target="_blank"&gt;Ring 0&lt;/a&gt; debugger from Compuware. Though SoftICE is no longer an offering from Compuware, it's use is still very common. While the author now uses &lt;a href="http://www.microsoft.com/whdc/devtools/debugging/default.mspx" target="_blank"&gt;WinDbg&lt;/a&gt; in place of SoftICE, some analysts have turned to &lt;a href="http://www.ollydbg.de/" target="_blank"&gt;OllyDbg&lt;/a&gt;. It is presumed that once Compuware decides to sell SoftICE, the debugger will regain it's previous popularity.&lt;br/&gt;
&lt;br/&gt;
PE Tools is used to dump either a partial (region) or full in-memory image of an executable. It also includes the ability to automatically remove "Anti Dump Protection", and find the original OEP (&lt;a href="http://www.csn.ul.ie/%7Ecaolan/publink/winresdump/winresdump/doc/pefile.html" target="_blank"&gt;AddressOfEntryPoint&lt;/a&gt; value of the &lt;code&gt;IMAGE_OPTIONAL_HEADER&lt;/code&gt; structure). This tool would be used with a packed or encrypted executable. After the decompression or decryption occurs, PE Tools would be used to copy the image from memory for further analysis.&lt;br/&gt;
&lt;br/&gt;
IDA is used to perform a static analysis on-disk, while a debugger is used to interrogate the executing program while in-memory. Based on the tools, this leads to the observation that a Protection Scheme must be functional in two environments - on-disk and in-memory. In the virus research community, challenging disassembly occurs in the anti-disassembly layer, while the implementation deterring dynamic analysis is known as a anti-debug layer.&lt;br/&gt;
&lt;br/&gt;
&lt;h3&gt;Unix and Linux&lt;/h3&gt;For Unix and Linux, &lt;a href="http://www.gnu.org/software/binutils/manual/html_chapter/binutils_4.html" target="_blank"&gt;objdump&lt;/a&gt; (with it's PERL based wrapper &lt;a href="http://packetstormsecurity.org/linux/reverse-engineering/dasm" target="_blank"&gt;dasm&lt;/a&gt;) and &lt;a href="http://sources.redhat.com/gdb/" target="_blank"&gt;gdb&lt;/a&gt; are two available tools. gdb supports debugging of C, C++, Java, Fortran and Assembly among other languages. In addition, gdb is designed to work closely with the GNU Compiler Collection (GCC). objdump and dasm collectively act as full disassembler. Alternately, one can run Windows applications such as IDA on Linux using &lt;a href="http://www.winehq.org/" target="_blank"&gt;Wine&lt;/a&gt;, which acts as a compatibility layer for running Windows programs on Linux. Kris Kaspersky introduces additional tools and details procedures specific to the ELF file format in &lt;em&gt;Hacker Disassembling Uncovered&lt;/em&gt;.&lt;br/&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3602674777707139629-7283356867570110406?l=kc-lui.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kc-lui.blogspot.com/feeds/7283356867570110406/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3602674777707139629&amp;postID=7283356867570110406' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3602674777707139629/posts/default/7283356867570110406'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3602674777707139629/posts/default/7283356867570110406'/><link rel='alternate' type='text/html' href='http://kc-lui.blogspot.com/2008/11/reverse-engineering-tools.html' title='Reverse Engineering Tools'/><author><name>lui</name><uri>http://www.blogger.com/profile/08679538620572861199</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09005455948053450369'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3602674777707139629.post-3621828859963686679</id><published>2008-11-06T23:41:00.003+08:00</published><updated>2009-12-15T03:00:39.820+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='life'/><title type='text'>人生第一筆薪水</title><content type='html'>就在今天&lt;br/&gt;
我拿到人生第一筆薪水了&lt;br/&gt;
真是莫名的感動&lt;br/&gt;
&lt;br/&gt;
因為八九十月沒收入　債台高築&lt;br/&gt;
償還債務後也剩不下來&lt;br/&gt;
但我還是要好好記念今天　哈&lt;br/&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3602674777707139629-3621828859963686679?l=kc-lui.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kc-lui.blogspot.com/feeds/3621828859963686679/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3602674777707139629&amp;postID=3621828859963686679' title='1 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3602674777707139629/posts/default/3621828859963686679'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3602674777707139629/posts/default/3621828859963686679'/><link rel='alternate' type='text/html' href='http://kc-lui.blogspot.com/2008/11/blog-post.html' title='人生第一筆薪水'/><author><name>lui</name><uri>http://www.blogger.com/profile/08679538620572861199</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09005455948053450369'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3602674777707139629.post-5482380481174169289</id><published>2008-11-03T01:02:00.008+08:00</published><updated>2009-12-14T19:35:43.624+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C/C++'/><title type='text'>struct的特別用法</title><content type='html'>&lt;pre class="cpp" name="code"&gt;
#include &lt;stdio.h&gt;

typedef struct A {
    int up : 1;
    int down : 1;
    int left : 1;
    int right : 1;
}Cell;

int main(void) {
    Cell c;

    c.up = c.down = c.left = c.right = 0;
    c.down = 1;
    printf("%d %d\n", sizeof(Cell), sizeof c);
    printf("%d %d %d %d\n", c.up &amp;amp; 1, c.down &amp;amp; 1, c.left &amp;amp; 1, c.right &amp;amp; 1);
    printf("%d %d %d %d\n", c.up, c.down, c.left, c.right);
    return 0;
}
&lt;/pre&gt;
結果:&lt;br/&gt;
4 4&lt;br/&gt;
0 1 0 0&lt;br/&gt;
0 -1 0 0&lt;br/&gt;
&lt;br/&gt;
宣告的變數會變成bit-field　struct因padding大小是4個byte.&lt;br/&gt;
裡面的變數都是bit　只能做bit operator　否則結果不是你想要的.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3602674777707139629-5482380481174169289?l=kc-lui.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kc-lui.blogspot.com/feeds/5482380481174169289/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3602674777707139629&amp;postID=5482380481174169289' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3602674777707139629/posts/default/5482380481174169289'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3602674777707139629/posts/default/5482380481174169289'/><link rel='alternate' type='text/html' href='http://kc-lui.blogspot.com/2008/11/struct.html' title='struct的特別用法'/><author><name>lui</name><uri>http://www.blogger.com/profile/08679538620572861199</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09005455948053450369'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3602674777707139629.post-166781760134912778</id><published>2008-10-27T22:36:00.003+08:00</published><updated>2009-12-15T03:04:49.671+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='music'/><title type='text'>Bizarre Love Triangle</title><content type='html'>Every time I think of you&lt;br/&gt;
I get a shot right through into a bolt of blue&lt;br/&gt;
It's no problem of mine but it's a problem I find&lt;br/&gt;
Living a life that I can't leave behind&lt;br/&gt;
There's no sense in telling me&lt;br/&gt;
The wisdom of a fool won't set you free&lt;br/&gt;
But that's the way that it goes&lt;br/&gt;
And its what nobody knows&lt;br/&gt;
And every day my confusion grows&lt;br/&gt;
Every time I see you falling&lt;br/&gt;
I get down on my knees and pray&lt;br/&gt;
I'm waiting for that final moment&lt;br/&gt;
You'll say the words that I can't say&lt;br/&gt;
&lt;br/&gt;
I feel fine and I feel good&lt;br/&gt;
I feel like I never should&lt;br/&gt;
Whenever I get this way, I just don't know what to say&lt;br/&gt;
Why cant we be ourselves like we were yesterday&lt;br/&gt;
I'm not sure what this could mean&lt;br/&gt;
I don't think youre what you seem&lt;br/&gt;
I do admit to myself&lt;br/&gt;
That if I hurt someone else&lt;br/&gt;
Then wed never see just what were meant to be&lt;br/&gt;
Every time I see you falling&lt;br/&gt;
I get down on my knees and pray&lt;br/&gt;
I'm waiting for that final moment&lt;br/&gt;
You'll say the words that I cant say&lt;br/&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3602674777707139629-166781760134912778?l=kc-lui.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kc-lui.blogspot.com/feeds/166781760134912778/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3602674777707139629&amp;postID=166781760134912778' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3602674777707139629/posts/default/166781760134912778'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3602674777707139629/posts/default/166781760134912778'/><link rel='alternate' type='text/html' href='http://kc-lui.blogspot.com/2008/10/bizarre-love-triangle.html' title='Bizarre Love Triangle'/><author><name>lui</name><uri>http://www.blogger.com/profile/08679538620572861199</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09005455948053450369'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3602674777707139629.post-1189726076601813755</id><published>2008-10-17T23:16:00.003+08:00</published><updated>2009-12-15T03:05:23.837+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='symbian'/><title type='text'>Symbian S60 5th Edition</title><content type='html'>Symbian的第五版在10/3 released&lt;br/&gt;
這版中主要加強的部份是多媒體、網路、可靠度和觸控介面&lt;br/&gt;
&lt;br/&gt;
第五版中優化攝影機的codec(宽螢幕影相儲存能力)。使用者設定參數來調控照片的balance, color and sharpness。次外，第五版包含照片和影片的編攝功能，讓使用者直接在mobile上修改並分享。&lt;br/&gt;
&lt;br/&gt;
隨著寬螢幕 nHD的支援，現在可以使用寬螢幕模式來看照片或影片，支援的影片格式包括MP3, AAC, H.264, Windows Media, Flash Video等。&lt;br/&gt;
&lt;br/&gt;
內建瀏覽器和支援Flash Lite，加上寬螢幕和觸控介面的支援可以令瀏覽網頁更方便。&lt;br/&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3602674777707139629-1189726076601813755?l=kc-lui.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kc-lui.blogspot.com/feeds/1189726076601813755/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3602674777707139629&amp;postID=1189726076601813755' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3602674777707139629/posts/default/1189726076601813755'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3602674777707139629/posts/default/1189726076601813755'/><link rel='alternate' type='text/html' href='http://kc-lui.blogspot.com/2008/10/symbian-s60-5th-edition.html' title='Symbian S60 5th Edition'/><author><name>lui</name><uri>http://www.blogger.com/profile/08679538620572861199</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09005455948053450369'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3602674777707139629.post-5897223587977241241</id><published>2008-10-04T00:43:00.003+08:00</published><updated>2009-12-15T03:02:20.508+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='life'/><title type='text'>英名一世?</title><content type='html'>沒想到現在這麼囧&lt;br/&gt;
&lt;br/&gt;
一直都是學最新的東西&lt;br/&gt;
&lt;br/&gt;
現在居然要學MFC MFC  MFC   MFC    MFC     MFC      MFC&lt;br/&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3602674777707139629-5897223587977241241?l=kc-lui.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kc-lui.blogspot.com/feeds/5897223587977241241/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3602674777707139629&amp;postID=5897223587977241241' title='4 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3602674777707139629/posts/default/5897223587977241241'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3602674777707139629/posts/default/5897223587977241241'/><link rel='alternate' type='text/html' href='http://kc-lui.blogspot.com/2008/10/blog-post.html' title='英名一世?'/><author><name>lui</name><uri>http://www.blogger.com/profile/08679538620572861199</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09005455948053450369'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3602674777707139629.post-7049713007978788694</id><published>2008-10-01T23:39:00.003+08:00</published><updated>2009-12-15T03:01:55.728+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C/C++'/><title type='text'>default constructor</title><content type='html'>C++中預設建構子就是沒有參數的建構子&lt;br/&gt;
&lt;br/&gt;
一般大多數人都有以下&lt;span style="font-size:130%;"&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;錯誤&lt;/span&gt;&lt;/span&gt;觀念：&lt;br/&gt;
1.class沒有定義預設建構子　compiler就會自動產生一個&lt;br/&gt;
2.compiler產生出來的預設建構子中　會為member data設預設值&lt;br/&gt;
&lt;br/&gt;
在C++ standard(ISO/IEC 14882)中說明：&lt;br/&gt;
"The implementation will implicitly declare these member functions for a class type when the program does not explicitly declare them, except as noted in 12.1. The implementation will implicitly define them if they are used"&lt;br/&gt;
&lt;br/&gt;
當compiler有需要而又沒有時才會產生出來　所以沒需要時就不會產生&lt;br/&gt;
&lt;br/&gt;
那甚麼時候需要呢!　文件中說明：&lt;br/&gt;
"If there is no user-declared constructor for class X, a default constructor is implicitly declared. An &lt;span style="font-style: italic;"&gt;implicitly-declared&lt;/span&gt; default constructor is an inline public member of its class. A constructor is &lt;span style="font-style: italic; font-weight: bold;"&gt;trivial&lt;/span&gt;&lt;span style="font-weight: bold;"&gt; &lt;/span&gt;if it is an implicitly-declared default constructor and if:
— its class has no virtual functions (10.3) and no virtual base classes (10.1), and
— all the direct base classes of its class have trivial constructors, and
— for all the nonstatic data members of its class that are of class type (or array thereof), each such class has a trivial constructor.
Otherwise, the constructor is non-trivial."&lt;br/&gt;
&lt;br/&gt;
所以說需要的定義取決於 1.virtual functions, 2.virtual inherited, 3.base class and 4.data members.&lt;br/&gt;
&lt;br/&gt;
1.virtual functions&lt;br/&gt;
當一個類別定義virtual functions後，每一個物件都必須有一個virtual function table記錄virtual function的位址，因此compiler會自動擴張物件的data member，產生這個table並且加入一個指標指向這個table。&lt;br/&gt;
&lt;br/&gt;
2.virtual inherited&lt;br/&gt;
(待補)&lt;br/&gt;
&lt;br/&gt;
3.base class&lt;br/&gt;
當一個class沒有&lt;span style="font-weight: bold;"&gt;任何&lt;/span&gt;預設建構子而它的base class有預設建構子時，那麼必須需呼叫base class的預設建構子，所以compiler自動擴張一個預設建構子，其中呼叫bass class的建構子。&lt;br/&gt;
&lt;br/&gt;
如果存在建構子的話，compiler會擴張建構子做上述事情而不擴張一個預設建構子。文件的解析是由於使用者定義的建構子存在下就不會隱含產生預設建構子。&lt;br/&gt;
&lt;br/&gt;
4.data members&lt;br/&gt;
同理。當data member中，存在至少一個物件有預設建構子時。&lt;br/&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3602674777707139629-7049713007978788694?l=kc-lui.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kc-lui.blogspot.com/feeds/7049713007978788694/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3602674777707139629&amp;postID=7049713007978788694' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3602674777707139629/posts/default/7049713007978788694'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3602674777707139629/posts/default/7049713007978788694'/><link rel='alternate' type='text/html' href='http://kc-lui.blogspot.com/2008/10/default-constructor.html' title='default constructor'/><author><name>lui</name><uri>http://www.blogger.com/profile/08679538620572861199</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09005455948053450369'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3602674777707139629.post-3870664167064878610</id><published>2008-10-01T22:11:00.002+08:00</published><updated>2009-12-15T03:06:14.354+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='life'/><title type='text'>18</title><content type='html'>記念一下&lt;br/&gt;
&lt;br/&gt;
我將是公司的第18位RD&lt;br/&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3602674777707139629-3870664167064878610?l=kc-lui.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kc-lui.blogspot.com/feeds/3870664167064878610/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3602674777707139629&amp;postID=3870664167064878610' title='3 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3602674777707139629/posts/default/3870664167064878610'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3602674777707139629/posts/default/3870664167064878610'/><link rel='alternate' type='text/html' href='http://kc-lui.blogspot.com/2008/10/18.html' title='18'/><author><name>lui</name><uri>http://www.blogger.com/profile/08679538620572861199</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09005455948053450369'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3602674777707139629.post-2786050965091773276</id><published>2008-09-26T15:53:00.002+08:00</published><updated>2009-12-15T03:06:57.148+08:00</updated><title type='text'>創業成功的必要條件</title><content type='html'>規則#1：擁有一個具爭議性的策略。尋找反直覺的構想，然後執行。如果你照規矩來，你只會流於一般。區別才是關鍵。困難的是，你必須判斷正確。&lt;br/&gt;
&lt;br/&gt;
規則#2：打破商業陳規，但不可用詐騙、說謊或偷竊的方式。這麼做，你將落得眾叛親離，失去忠誠員工對你的信賴。&lt;br/&gt;
&lt;br/&gt;
規則#3：想辦法籌得一些錢，但不要太多。小數目的創業資本會迫使你錙銖必較、節省支出、追求效率，並且努力尋找新的生產途徑。&lt;br/&gt;
&lt;br/&gt;
規則#4：具備一個理想。McNealy說：「人類大都是金錢驅動的，但他們也喜歡有一點精神上的收入。」例如，昇陽創造的開放原始碼學科維基Curriki，就解決了McNealy和他兒子作小學報告所碰到的問題。&lt;br/&gt;
&lt;br/&gt;
規則#5：放手去作，但慎選伴侶。投入你全副的心力和靈魂去開創事業，但請在結婚之前。McNealy直到39歲才結婚，但婚後四個兒子接連出生。他建議：「你一生中最重要的決定就是和誰結婚生子。挑選一個配偶或重要的另一半，或任何你喜歡的伴侶。只要確定你挑了一個好人。這是一個創業者給你的一些實在的技術性建議。」&lt;br/&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3602674777707139629-2786050965091773276?l=kc-lui.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kc-lui.blogspot.com/feeds/2786050965091773276/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3602674777707139629&amp;postID=2786050965091773276' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3602674777707139629/posts/default/2786050965091773276'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3602674777707139629/posts/default/2786050965091773276'/><link rel='alternate' type='text/html' href='http://kc-lui.blogspot.com/2008/09/blog-post_26.html' title='創業成功的必要條件'/><author><name>lui</name><uri>http://www.blogger.com/profile/08679538620572861199</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09005455948053450369'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3602674777707139629.post-1153336036247219444</id><published>2008-09-25T17:55:00.004+08:00</published><updated>2009-12-15T03:03:21.592+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C/C++'/><title type='text'>tricky skill (1) in C</title><content type='html'>&lt;pre class="cpp" name="code"&gt;
struct rumble {
  char c[1];
};

struct rumble *p = (struct rumble*) malloc(sizeof(struct rumble) + 5);
&lt;/pre&gt;
在C裡　有一個技巧就是在struct最後宣告一個單一元素的陣列&lt;br/&gt;
於是在malloc時就能擁有可變大小的struct rumble了&lt;br/&gt;
&lt;br/&gt;
當然這個技巧也能用在C++　但這會與compiler有關&lt;br/&gt;
因為雖然宣告在最後　compile時可能會產生額外的資料在最尾端&lt;br/&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3602674777707139629-1153336036247219444?l=kc-lui.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kc-lui.blogspot.com/feeds/1153336036247219444/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3602674777707139629&amp;postID=1153336036247219444' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3602674777707139629/posts/default/1153336036247219444'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3602674777707139629/posts/default/1153336036247219444'/><link rel='alternate' type='text/html' href='http://kc-lui.blogspot.com/2008/09/tricky-skill-1-in-c.html' title='tricky skill (1) in C'/><author><name>lui</name><uri>http://www.blogger.com/profile/08679538620572861199</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09005455948053450369'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3602674777707139629.post-9037987785554433676</id><published>2008-09-24T13:08:00.005+08:00</published><updated>2009-12-15T03:04:08.318+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C/C++'/><title type='text'>預設值和多型的陷阱</title><content type='html'>&lt;pre class="cpp" name="code"&gt;
class A {
  virtual void f(int i = 10);
};

class B: public A {
  void f(int i = 20);
};

A* a = B();
a-&gt;f();
&lt;/pre&gt;
這題多型很簡單　a-&gt;f()會呼叫class B裡的f()&lt;br/&gt;
但問題是如果印i出來　值會是多少呢&lt;br/&gt;
&lt;br/&gt;
答案是i = 10&lt;br/&gt;
原因是預設引數是在編譯時期根據a的型別確定了&lt;br/&gt;
所以i就被初始為10&lt;br/&gt;
最後印出來就是10了&lt;br/&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3602674777707139629-9037987785554433676?l=kc-lui.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kc-lui.blogspot.com/feeds/9037987785554433676/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3602674777707139629&amp;postID=9037987785554433676' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3602674777707139629/posts/default/9037987785554433676'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3602674777707139629/posts/default/9037987785554433676'/><link rel='alternate' type='text/html' href='http://kc-lui.blogspot.com/2008/09/blog-post_24.html' title='預設值和多型的陷阱'/><author><name>lui</name><uri>http://www.blogger.com/profile/08679538620572861199</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09005455948053450369'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3602674777707139629.post-6159144450694035901</id><published>2008-09-10T00:48:00.002+08:00</published><updated>2009-12-15T03:07:17.744+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='music'/><title type='text'>last order</title><content type='html'>歌名:last order&lt;br/&gt;
演唱:陳奕迅&lt;br/&gt;
作曲:Eric Kwok,  編曲:Eric Kwok&lt;br/&gt;
監製:Eric Kwok,  填詞:黃偉文&lt;br/&gt;
&lt;br/&gt;
沒關係　真的沒關係　我也許　早就該回去&lt;br/&gt;
再一杯　我告訴自己　到此為止　乾了不再續&lt;br/&gt;
麻煩你　加冰威士忌　對不起　來個DOUBLE的&lt;br/&gt;
喝到這裡　終於夠勇氣　說一個經歷&lt;br/&gt;
&lt;br/&gt;
＊那晚下雨　在這店裡　也放著這首曲&lt;br/&gt;
　有個男子　搭上一個女子　反正失戀　他當然不介意　有段艷遇&lt;br/&gt;
　只是回到　他的家裡　十幾坪　家徒四壁&lt;br/&gt;
　一聲不響　那女的　掉頭離去&lt;br/&gt;
　就像　三個小時前　未婚妻　初次到來　嫌棄的樣子&lt;br/&gt;
（就像　我的未婚妻　對不起　好像說成是我的樣子　我是沒關係）&lt;br/&gt;
&lt;br/&gt;
沒關係　真的沒關係　一晚上　就失戀兩次&lt;br/&gt;
那男子　還不懂懷疑　到底自己是否沒出息&lt;br/&gt;
不客氣　別給我ICE TEA 客人們不是我嚇跑的&lt;br/&gt;
別看著我　這個不過是　我朋友的經歷&lt;br/&gt;
&lt;br/&gt;
Repeat ＃()&lt;br/&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3602674777707139629-6159144450694035901?l=kc-lui.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kc-lui.blogspot.com/feeds/6159144450694035901/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3602674777707139629&amp;postID=6159144450694035901' title='1 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3602674777707139629/posts/default/6159144450694035901'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3602674777707139629/posts/default/6159144450694035901'/><link rel='alternate' type='text/html' href='http://kc-lui.blogspot.com/2008/09/last-order.html' title='last order'/><author><name>lui</name><uri>http://www.blogger.com/profile/08679538620572861199</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09005455948053450369'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3602674777707139629.post-2219950567406201033</id><published>2008-09-07T15:54:00.002+08:00</published><updated>2009-12-15T03:25:51.087+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='life'/><title type='text'>誰才是主人呀</title><content type='html'>我的貓每天都跟我爭椅子座&lt;br/&gt;
有沒有搗錯&lt;br/&gt;
&lt;br/&gt;
每次一從電腦前離開&lt;br/&gt;
牠馬上坐上去　趕也不走&lt;br/&gt;
分明是要爭主人位咩&lt;br/&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3602674777707139629-2219950567406201033?l=kc-lui.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kc-lui.blogspot.com/feeds/2219950567406201033/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3602674777707139629&amp;postID=2219950567406201033' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3602674777707139629/posts/default/2219950567406201033'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3602674777707139629/posts/default/2219950567406201033'/><link rel='alternate' type='text/html' href='http://kc-lui.blogspot.com/2008/09/blog-post_07.html' title='誰才是主人呀'/><author><name>lui</name><uri>http://www.blogger.com/profile/08679538620572861199</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09005455948053450369'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3602674777707139629.post-5145309598787836134</id><published>2008-09-01T12:39:00.004+08:00</published><updated>2009-12-15T03:18:39.710+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='me'/><title type='text'>弱雞</title><content type='html'>前天被說是弱雞&lt;br/&gt;
我卻一點都不能反駁&lt;br/&gt;
唉...&lt;br/&gt;
&lt;br/&gt;
我的右手呀&lt;br/&gt;
自從五月一場籃球比賽受傷後&lt;br/&gt;
超過一公斤的東西都不太能拿&lt;br/&gt;
拿了就受傷了&lt;br/&gt;
搬東西也不行&lt;br/&gt;
&lt;br/&gt;
幹~~~&lt;br/&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3602674777707139629-5145309598787836134?l=kc-lui.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kc-lui.blogspot.com/feeds/5145309598787836134/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3602674777707139629&amp;postID=5145309598787836134' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3602674777707139629/posts/default/5145309598787836134'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3602674777707139629/posts/default/5145309598787836134'/><link rel='alternate' type='text/html' href='http://kc-lui.blogspot.com/2008/09/blog-post.html' title='弱雞'/><author><name>lui</name><uri>http://www.blogger.com/profile/08679538620572861199</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09005455948053450369'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3602674777707139629.post-565828480119654396</id><published>2008-08-28T14:17:00.003+08:00</published><updated>2009-12-15T03:09:16.533+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C/C++'/><title type='text'>多型的陷阱</title><content type='html'>&lt;pre class="cpp" name="code"&gt;
class A {...};
class B {...};
class C: public A, private B {...};

A a = new C();
B b = new C();
&lt;/pre&gt;
在C++中，繼承有public, protected and private&lt;br/&gt;
如果使用private的話　第6行編譯是不會過的　因為privated下是看不到的&lt;br/&gt;
如果是protected　則在可視scope下才能用&lt;br/&gt;
&lt;br/&gt;
這點是java或其他OO語言沒有的&lt;br/&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3602674777707139629-565828480119654396?l=kc-lui.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kc-lui.blogspot.com/feeds/565828480119654396/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3602674777707139629&amp;postID=565828480119654396' title='2 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3602674777707139629/posts/default/565828480119654396'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3602674777707139629/posts/default/565828480119654396'/><link rel='alternate' type='text/html' href='http://kc-lui.blogspot.com/2008/08/blog-post_28.html' title='多型的陷阱'/><author><name>lui</name><uri>http://www.blogger.com/profile/08679538620572861199</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09005455948053450369'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3602674777707139629.post-3473792215561357584</id><published>2008-08-27T12:42:00.005+08:00</published><updated>2009-12-15T03:10:05.854+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C/C++'/><title type='text'>差點被考到的程式碼</title><content type='html'>昨天面試　其中一個主管很在意coding能力&lt;br/&gt;
我也跟他說我coding很好&lt;br/&gt;
他就要考考我&lt;br/&gt;
考了兩題後　他發現太無趣了　就從一堆題目中找了一題出來&lt;br/&gt;
說這題過去沒幾個人講的出來&lt;br/&gt;
&lt;pre class="cpp" name="code"&gt;
#define fun(A, b) (int)(&amp;(((A *)0)-&gt;b))

typedef struct {
  char str[40];
  int type;
  int maxLen;
} intf;
&lt;/pre&gt;
問題是fun(intf, maxLen)的值為多少&lt;br/&gt;
&lt;br/&gt;
看到第一眼時　先假裝鎮定　但不解 A * 的作用&lt;br/&gt;
因為腦殘沒看到typedef　想說A替換後只是變數不是型別&lt;br/&gt;
所以就靠推理的方式理解成強制轉型為pointer　並以此位置為0&lt;br/&gt;
所以b的位置就是 sizeof(char) * 40 + sizeof(int)&lt;br/&gt;
答案是對的　還告訴我它叫offset　差點被他唬到&lt;br/&gt;
&lt;br/&gt;
回家查了一下&lt;br/&gt;
原來這個code是在stddef.h裡&lt;br/&gt;
目的是做出泛型計算變數在struct的offset&lt;br/&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3602674777707139629-3473792215561357584?l=kc-lui.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kc-lui.blogspot.com/feeds/3473792215561357584/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3602674777707139629&amp;postID=3473792215561357584' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3602674777707139629/posts/default/3473792215561357584'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3602674777707139629/posts/default/3473792215561357584'/><link rel='alternate' type='text/html' href='http://kc-lui.blogspot.com/2008/08/blog-post.html' title='差點被考到的程式碼'/><author><name>lui</name><uri>http://www.blogger.com/profile/08679538620572861199</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09005455948053450369'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3602674777707139629.post-695903867184313230</id><published>2008-08-01T23:29:00.004+08:00</published><updated>2009-12-15T03:24:26.182+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='music'/><title type='text'>100種生活</title><content type='html'>詞 鍾成虎 曲 盧廣仲&lt;br/&gt;
*&lt;br/&gt;
整個世界 停止 不轉動 很寂寞&lt;br/&gt;
走在海邊 數著 螢火蟲 好困惑&lt;br/&gt;
想要的生活怎麼有一百種&lt;br/&gt;
不想掉進這深深 漩渦&lt;br/&gt;
&lt;br/&gt;                                                           
整個海浪 擺動 柔軟地 舉起我&lt;br/&gt;
孤獨給我 自由 猶豫得 好感動&lt;br/&gt;
想要的生活怎麼有一百種&lt;br/&gt;
該怎麼走 誰來告訴我 wow&lt;br/&gt;
&lt;br/&gt;                                                       
每當我背對星空&lt;br/&gt;
抱著地球&lt;br/&gt;
發現自己其實脆弱 不敢說&lt;br/&gt;
當我背對星空 不段摸索&lt;br/&gt;
愛情漸漸萎縮 我猜不透&lt;br/&gt;
無邊的宇宙 哪裡有我想要的生活&lt;br/&gt;
&lt;br/&gt;
repeat *&lt;br/&gt;
&lt;br/&gt;
原來一百種 要在很久很久&lt;br/&gt;
以後才會懂 我的一百種生活&lt;br/&gt;
&lt;br/&gt;
&lt;div class="Sidebody"&gt;
  &lt;embed hidden="false" width="160" src="http://plum.cs.nccu.edu.tw/~g9506/music/100_kinds_live.mp3" autostart="false" height="16"&gt;
  &lt;/embed&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3602674777707139629-695903867184313230?l=kc-lui.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kc-lui.blogspot.com/feeds/695903867184313230/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3602674777707139629&amp;postID=695903867184313230' title='2 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3602674777707139629/posts/default/695903867184313230'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3602674777707139629/posts/default/695903867184313230'/><link rel='alternate' type='text/html' href='http://kc-lui.blogspot.com/2008/08/100.html' title='100種生活'/><author><name>lui</name><uri>http://www.blogger.com/profile/08679538620572861199</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09005455948053450369'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3602674777707139629.post-6925418916482016721</id><published>2008-07-26T12:02:00.003+08:00</published><updated>2009-12-15T03:13:54.201+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>google code jam第三題</title><content type='html'>google code jam今天早上比了第一場&lt;br/&gt;
看了一下第三題&lt;br/&gt;
問題是 3 + 5^0.5 取n次方後　求整數前三位數字&lt;br/&gt;
&lt;br/&gt;
看起來很簡單　但一看就知道是誤差問題&lt;br/&gt;
看到解出來的人的解答　真的突然覺得自己數學變好差&lt;br/&gt;
早知道平常應該繼續唸的&lt;br/&gt;
&lt;br/&gt;
這題n取很大時會有誤差　所以不能硬幹&lt;br/&gt;
使用數學方法　設：&lt;br/&gt;
3 + 5^0.5  = x&lt;br/&gt;
         5 = x^2 - 6x + 9&lt;br/&gt;
         0 = x^2 - 6x + 4&lt;br/&gt;
根據n對公式取次方&lt;br/&gt;
最後再解方程&lt;br/&gt;
這樣誤差就消失了&lt;br/&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3602674777707139629-6925418916482016721?l=kc-lui.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kc-lui.blogspot.com/feeds/6925418916482016721/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=3602674777707139629&amp;postID=6925418916482016721' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3602674777707139629/posts/default/6925418916482016721'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3602674777707139629/posts/default/6925418916482016721'/><link rel='alternate' type='text/html' href='http://kc-lui.blogspot.com/2008/07/google-code-jam.html' title='google code jam第三題'/><author><name>lui</name><uri>http://www.blogger.com/profile/08679538620572861199</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09005455948053450369'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry></feed>