12/26/2007

VS2005 and VS2008 .sln file icon incorrect

I had installed VS2005 and VS2008 on Vista Business, both work fine. But today, I found .sln file icon losted and cannot open it with double-click. So I associate .sln with Visual Studio Version Selector, it works again, but the file icon is incorret.

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

1. Define the _CRT_RAND_S macro before the #include <stdlib.h> .
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++

static unsigned int const value = Fibonacci<N-1>::value + Fibonacci<N-2>::value;
};

template<>
struct Fibonacci<1> {
static unsigned int const value = 1u;
};

template<>
struct Fibonacci<2> {
static unsigned int const value = 2u;
};

int main(int argc, char *argv[]) {
unsigned int v3 = Fibonacci<3>::value;
unsigned int v9 = Fibonacci<9>::value;

return (0);
}


12/11/2007

A sealed class in C++

I want a 'sealed' class in native C++ just like 'sealed' in C++/CLI and C# or 'final' in Java. I googled it then got following solution.

template<typename T>
class DeriveLock {
private:

DeriveLock() {}
~DeriveLock() {}
friend T;
};

class SealedClass : virtual public DeriveLock<SealedClass> {
};

You can found above sample code at Bjarne Stroustrup's article.