Quiz on C++ Object Model
Posted on March 4th, 2010 at 0:07 by fr3@K

這幾個月忙於工作, 這個部落格都快被我給荒廢掉了. 昨晚終於花了時間完成了一篇積了一兩個月, 說明 virtual function 在執行時期的 override 過程以及 virtual function 與 constructor/destructor 混搭結果 的文字.

今天我準備了個題目給花了時間看了它的朋友, 當作一次對小弟的該題目說明能力的測驗. 請問, 下面的 code snip 的輸出結果是什麼?
(more…)

del.icio.us:Quiz on C++ Object Model digg:Quiz on C++ Object Model spurl:Quiz on C++ Object Model newsvine:Quiz on C++ Object Model furl:Quiz on C++ Object Model Y!:Quiz on C++ Object Model 黑米共享書籤:Quiz on C++ Object Model 推推王:Quiz on C++ Object Model
當 Constructor 遇上 Virtual Function
Posted on March 3rd, 2010 at 0:19 by fr3@K

Background

不知道你有沒有過這樣的經驗 – 想要在父類的 constructor 裏面呼叫被子類 override (或是 implement) 的 (pure) virtual function?
(more…)

del.icio.us:當 Constructor 遇上 Virtual Function digg:當 Constructor 遇上 Virtual Function spurl:當 Constructor 遇上 Virtual Function newsvine:當 Constructor 遇上 Virtual Function furl:當 Constructor 遇上 Virtual Function Y!:當 Constructor 遇上 Virtual Function 黑米共享書籤:當 Constructor 遇上 Virtual Function 推推王:當 Constructor 遇上 Virtual Function
[Update] boost::decay documentation issue
Posted on January 14th, 2010 at 17:35 by fr3@K

The issue with boost::decay documentation that I blogged about 10 days ago has been fixed in trunk.

del.icio.us:[Update] boost::decay documentation issue digg:[Update] boost::decay documentation issue spurl:[Update] boost::decay documentation issue newsvine:[Update] boost::decay documentation issue furl:[Update] boost::decay documentation issue Y!:[Update] boost::decay documentation issue 黑米共享書籤:[Update] boost::decay documentation issue 推推王:[Update] boost::decay documentation issue
boost::decay documentation issue
Posted on January 4th, 2010 at 20:48 by fr3@K

前陣子看了 Hubert 的 一個 boost::exception 的例子, 猛然注意到自己不確定 boost::decay 的作用.

去看了它的 文件, 才發現文件不盡然正確… 已 submit 了一個 ticket 給 Boost, 希望早日修正.

del.icio.us:boost::decay documentation issue digg:boost::decay documentation issue spurl:boost::decay documentation issue newsvine:boost::decay documentation issue furl:boost::decay documentation issue Y!:boost::decay documentation issue 黑米共享書籤:boost::decay documentation issue 推推王:boost::decay documentation issue
Bit-fu
Posted on January 3rd, 2010 at 11:40 by fr3@K

Did you know, for x is an integer, that -~x yields x + 1 and ~-x yields x - 1?

via: Advanced bit manipulation-fu.

del.icio.us:Bit-fu digg:Bit-fu spurl:Bit-fu newsvine:Bit-fu furl:Bit-fu Y!:Bit-fu 黑米共享書籤:Bit-fu 推推王:Bit-fu
Another Good Interview Question in C++
Posted on January 2nd, 2010 at 17:10 by fr3@K

elleryq 這篇 blog post 談到的 ctor (換成 dtor 也一樣) 呼叫 virtual function 狀況 (或說是 problem) 會是很好的 C++ programmer 面試題目. 可在口試時用以窺探 interviewee 對 C++ object model 的了解.
(more…)

del.icio.us:Another Good Interview Question in C++ digg:Another Good Interview Question in C++ spurl:Another Good Interview Question in C++ newsvine:Another Good Interview Question in C++ furl:Another Good Interview Question in C++ Y!:Another Good Interview Question in C++ 黑米共享書籤:Another Good Interview Question in C++ 推推王:Another Good Interview Question in C++
一看就知道 – 不 Thread-Safe 的 API
Posted on December 1st, 2009 at 13:37 by fr3@K

Very well put :)

當你發現回傳的是一個 char *,又沒有要求你特別 free 他,你是不是就該猜測他是回傳 function 內部的一個 static buffer 了呢?

Via: 從 inet_ntoa 看 thread safe 的 API.

del.icio.us:一看就知道 - 不 Thread-Safe 的 API digg:一看就知道 - 不 Thread-Safe 的 API spurl:一看就知道 - 不 Thread-Safe 的 API newsvine:一看就知道 - 不 Thread-Safe 的 API furl:一看就知道 - 不 Thread-Safe 的 API Y!:一看就知道 - 不 Thread-Safe 的 API 黑米共享書籤:一看就知道 - 不 Thread-Safe 的 API 推推王:一看就知道 - 不 Thread-Safe 的 API
What Happens When We Lie to the Compiler?
Posted on November 13th, 2009 at 12:57 by fr3@K

When you lie to your compiler, don’t be surprised to get results those differ from what you expect.

In this case, the coder promised his/her compiler the value of “value” won’t be changed, as it was declared const.

Therefore our best friend (yes, the compiler) who trusted the coder, thought “hey, I could cache this value in a register and not fetch it from RAM every time I reference it”, i.e. optimization.

If we change the code in the link slightly, so that function funcC would print *value before the assignment, one would see that the value of *value had actually been modified by function funcA. However, the modification was not visible in main, because the compiler was lied to as the coder explicitly told it that there would be no modification to value.

In the body of function funcC, though value was declared as a pointer to const instance, the compiler was smart enough to know it was lied to. There was a const_cast and a assignment, therefore, the modification to *value was reflected in the output.

del.icio.us:What Happens When We Lie to the Compiler? digg:What Happens When We Lie to the Compiler? spurl:What Happens When We Lie to the Compiler? newsvine:What Happens When We Lie to the Compiler? furl:What Happens When We Lie to the Compiler? Y!:What Happens When We Lie to the Compiler? 黑米共享書籤:What Happens When We Lie to the Compiler? 推推王:What Happens When We Lie to the Compiler?
So, You Think C++ is Slower than C
Posted on November 6th, 2009 at 2:01 by fr3@K

It is true that C++ provides programming constructs those consume more CPU cycles than it would when done without higher level of abstractions. But, hey, that’s the cost of abstractions, why pay when they are not needed?

Stop laying out your C++ design like Java. Avoid inheritance when possible. Don’t make every member function and destructor virtual without really thinking. They not only increase your run time overhead, they boost the complexity (read coupling) of your code like nothing else.

C++ does every C-style stuff the same way as C does. Not to mention it is capable of more compile time computation than C. I just fail to see how C++ could be slower than C in run time, seriously.

del.icio.us:So, You Think C++ is Slower than C digg:So, You Think C++ is Slower than C spurl:So, You Think C++ is Slower than C newsvine:So, You Think C++ is Slower than C furl:So, You Think C++ is Slower than C Y!:So, You Think C++ is Slower than C 黑米共享書籤:So, You Think C++ is Slower than C 推推王:So, You Think C++ is Slower than C
Boost.Lexical-Cast Alternatives
Posted on September 17th, 2009 at 21:49 by fr3@K

今天稍早, 跟一位同事聊到 Boost 的 lexical_cast. 打開了 Firefox 請出 Google, 想找到能幫助我介紹 lexical_cast 的資源. 意外地, Google 把我帶到讓我賺了介紹獎金, 現在跟我是同事的 Jeff, 談到 lexical_cast 的 文章.

在這篇文字的討論串, Jeff 寫道:

我覺得如果可以用這樣的寫法,那就太好了:

uint32_t ID = lexical_cast<auto>("1234567");

甚至最好是:

template <class From, class To = auto>
To lexical_cast(From s) {...}

uint32_t ID = lexical_cast("1234567");

Jeff Hung

(more…)

del.icio.us:Boost.Lexical-Cast Alternatives digg:Boost.Lexical-Cast Alternatives spurl:Boost.Lexical-Cast Alternatives newsvine:Boost.Lexical-Cast Alternatives furl:Boost.Lexical-Cast Alternatives Y!:Boost.Lexical-Cast Alternatives 黑米共享書籤:Boost.Lexical-Cast Alternatives 推推王:Boost.Lexical-Cast Alternatives

Page 1 of 8[ 1 ]2345»...Oldest