Let me tell you why you are here. You have come because you know something. What you know you can't explain but you feel it. You've felt it your whole life, felt that something is wrong with the world. You don't know what, but it's there like a splinter in your mind, driving you mad. It is this feeling that brought you to me. Do you know what I'm talking about?
12/26/2007
VS2005 and VS2008 .sln file icon incorrect
I spent all the afternoon to make a ton of mistakes, the final solution is: associate .sln with <osroot>\Program Files\Common Files\microsoft shared\MSEnv\VSLauncher.exe.
The headache had been resolved, but I cannot find the reality. The conclusion is more bigger and more danger.
12/25/2007
Pseudorandom number generation enhanced in VS2005
2. Does not need call srand function to generate the seed.
3. rans_s now has returned value which is type of errno_t, zero if successful.
4. Use this formula: dst_num = (unsigned int)((double)rand_num / (double)UINT_MAX * rand_max + rand_min) to specify the range[rand_min, rand_max] .
12/24/2007
程序员版<东邪西毒>
1. 每个programer都会经过这个阶段,见到一个program,就想知道program后面是什么。我很想告诉他,可能debug到program后面,你会发现没什么特别。回望之下,可能会觉得这一边更好。但我知道他不会听,以他的性格,自己不debug过又怎会甘心?
2. 去一个没去过的地方,希望可以闯出一个名堂,如果你以后在江湖上听到一个从不debug的英雄,那么一定是我。
3. 其实写一个program不是很容易,不过为了生活,很多人都会冒这个险。
4. 我很奇怪为什么会有C#,Anders Hejlsberg说人最大的烦恼就是记性太好。如果什么都可以忘了,以后的每一天都将会是一个新的开始。你说,那多开心。
5. 你知道programming和debugging的区别吗?debug越debugging越暖,program会越programming越寒。
6. 也许太久没有看program了,翌年的春天,我去了那人(Bill.Gates)的公司,我觉得很奇怪,那里根本没有program。
7. 他虽然是一个落泊的programer,但他的生活很有规律,每天都会来这里喝一杯酒,吃两碗饭,到月亮下山的时候他就会走。
8. 今年五黄临太岁,到处都是newbie。有newbie的地方一定有麻烦,有麻烦......,那我就有生意。我叫JoeM,我的职业就是帮助别人解除烦恼。
9. 在我出道的时候,我认识了一个人。因为他喜欢在computer边出没,所以很多年之后,他有个绰号叫Newbie。
This post is migrated from <Holy Joe's csdn blog at 9/28/2005>.12/16/2007
A small example of compute Fibonacci's formula statically in C++
template<unsigned int N>
struct Fibonacci {
template<>
struct Fibonacci<1> {
template<>
struct Fibonacci<2> {
int main(int argc, char *argv[]) {
unsigned int v9 = Fibonacci<9>::value;
return (0);
12/11/2007
A sealed class in C++
template<typename T>
class DeriveLock {
private:
~DeriveLock() {}
friend T;
class SealedClass : virtual public DeriveLock<SealedClass> {
};
You can found above sample code at Bjarne Stroustrup's article.
11/15/2007
It is upon the Trunk that a gentleman works
原文是以下粗体部分:
"君子务本(It is upon the Trunk that a gentleman works.)" -- Confucius
注意在上句中的Trunk是首字母大写的,Trunk在版本控制系统中是特定术语,可以不负责任地将其译作:主线或主干。而此眉批出自<论语.学而>,原文为:"子曰: 其为人也孝弟,而好犯上者,鲜矣; 不好犯上,而好作乱者,未之有也; 君子务本,本立而道生。孝弟也者,其为人之本欤!" 而此眉批恰如其分、一语双关的点出了第4章的主旨,堪称妙绝。虽然,svn-book中妙语接踵(这在技术文档中罕见),而其它章节却皆无眉批,因此第4章"君子务本"的眉批显得就格外抢眼了,也正因为它处皆无此处独有,方显得作者的手段(注: 不悟者可细品之,细品之后还不悟者,非吾之罪也)。
注: 文中提及'古典汉学'爱好者,而不说当下时髦用语'国学'爱好者,原因大体有二:
1. 所谓'古典汉学',本之于中,放之四海皆准,未闻有'国'者,'国学'一说,盖出自满清之后,为何?!;
2. 不明所以,打着'国学'奉旨乞食的招牌,到处贩卖祖产,真有伤国体也。
10/31/2007
LNK2028, LNK2019 without extern "C"
10/23/2007
Reversing string in C
void reverse(char s[]) {
int i, j;
for (i = 0, j = strlen(s) - 1; i < j; ++i, --j) {
But the above code can be improved. There is 'Pointer Version':
void reverse(char *s) {
char c;
while (*s++)
while (l < s) {
*l++ = *s;
*s-- = c;
The *strrev* in C standard library implements the same functionality, but generally implements in assembly code.
10/20/2007
Item not found: Could not find this item! on Vista
Try the following:
1. Open the command prompt.
2. Execute *dir /x* to display 8.3 file name
3. Execute *rd filename* the filename 8.3 format that u got it in step 2.
10/18/2007
The #end joke
Because, u can use the *# e n d* flag in ur gmail in order to indicate blogger to truncate the content after *# e n d* flag. It's a joke.
Organize IA-32 machine code in C++ class
#include <iostream>
#pragma pack(push, 1)
class MachineCode {
public:
#pragma pack(pop, 1)
typedef void (__stdcall *ProcCall)(void);
class Adapter {
public:
thunk_.proc_ = (unsigned long)proc - ((unsigned long)pthis + sizeof(thunk_));
::FlushInstructionCache(::GetCurrentProcess(), pthis, sizeof(thunk_));
return (true);
ProcCall GetProcCaller(void) {
static void DefProcCall(void) {
Then, I use the following code to call X::DefProcCall function:
Adapter x;
x.Init (&Adapter::DefProcCall, &x);
ProcCall call = x.GetProcCaller();
call();
The all magic is at 'reinterpret_cast<ProcCall>(
The jmp_ data member of MachineCode class stores 0xE9 that is 'jmp' instruction in IA-32. And the proc_ data member stores relative address since the ending address of the thunk_ which in Adapter class. So whole MachineCode class generate such IA-32 code 'jmp address'.
10/16/2007
[] Operator in IA-32 assembly code
The following C code:
int i;
i = 0x1234;
can be translate to assembly code which looks like this:
mov dword ptr [i], 1234h
the dword ptr means the content of variable i occupied 4 bytes. It is required because of IA-32 is byte addressable. And above mov instruction does not know how much storage requires for storing immediate number 1234h.
10/15/2007
Cannot install Microsoft Server 2003 SP2!
1. net stop cryptsvc
2. ren %systemroot%\system32\catroot2 old-catroot2
3. net start cryptsvc
10/14/2007
Manipulate bits in C
const int FIRST = 1 << 0;
const int SECOND = 1 << 1;
const int THIRD = 1 << 2;
Why defines the bit flag like this? Oh, just for clarity.
2. Setting bit flag:
int flags = 0;
flags |= FIRST;
flags |= SECOND;
flags |= THIRD;
if (flags & FIRST) {
printf("FIRST bit has been set.\n");
} else if (flags & SECOND) {
printf("SECOND bit has been set.\n");
}
...
3. Clearing bit flag:
flags &= ~FIRST;
flags &= ~SECOND;
...