随笔 - 31  文章 - 128  trackbacks - 0
<2024年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

常用链接

留言簿(5)

随笔分类(38)

随笔档案(31)

收藏夹(4)

College

High School

最新随笔

搜索

  •  

积分与排名

  • 积分 - 54311
  • 排名 - 408

最新评论

  • 1. re: [yc]详解link
  • 面试的时候面试官就问过我什么是编译和链接,我说编译就是把代码文件生成目标文件,链接就是把目标文件生成可执行文件,他说不对,又问我什么是动态链接,还问我预编译都做什么处理。。。都在这里找到了答案!!!!
  • --王至乾
  • 2. re: [yc]详解link
  • @刘伟
    我是说博主,不是叫你啊
  • --溪流
  • 3. re: [yc]详解link
  • 谁是石老师,我不是哈@溪流
  • --刘伟
  • 4. re: [yc]详解link
  • 石老师?我是溪流~
  • --溪流
  • 5. re: [yc]详解link
  • 期待楼主下文啊,多谢楼主了
  • --刘伟

阅读排行榜

评论排行榜

此处废弃,新家http://hi.baidu.com/shifan3

为什么要搬迁?
我打开这个编辑页面花了3个月
posted @ 2008-01-22 20:54 shifan3 阅读(1108) | 评论 (1)编辑 收藏
事实证明,调试黑箱+内核的程序
RP是关键
posted @ 2007-11-29 16:45 shifan3 阅读(1189) | 评论 (4)编辑 收藏
有恒性(G):
【结果解释】从测试来看,被试做事苟且敷衍,缺乏奉公守法的精神,缺乏远大的目标和崇高的理想,对人类社会没有绝对的责任感,甚至有时不惜知法犯法,不择手段,不过对于解决实际问题比较有效,不会浪费过多时间与精力。
【适合职业】艺术家、社会工作者、社会科学家、竞技运动员、作家、记者。
posted @ 2007-11-26 20:53 shifan3 阅读(954) | 评论 (2)编辑 收藏
转载自神的blog
http://blog.csdn.net/vbvan/archive/2007/10/30/1856481.aspx

搞挂你的C++编译器 

Play  with the compiler是一件很有趣的事情,编译死循环的程序便是其中之一。让我们和编译器一起做游戏吧~

1、Preprocess

a、Self Include(GCC only)
一般的编译器都有include嵌套层数的限制,所以你需要在适当的时候停止嵌套。利用GCC提供的__INCLUDE_LEVEL__可以很轻松的实现这一点。时间复杂度是na,n是每层的Self Include次数,a是嵌套层数。
在其它编译器中可以写出类似的代码,只是没这么简洁

#if __INCLUDE_LEVEL__<199
#include __FILE__
#include __FILE__
#endif

b、Macro Expansion Explosion
顾名思义,就是让Preprocess之后的代码量达到O(2n),比如下例:

#define F1(x) x,x
#define F2(x) F1(x),F1(x)
#define F3(x) F2(x),F2(x)
#define F4(x) F3(x),F3(x)
#define F5(x) F4(x),F4(x)
#define F6(x) F5(x),F5(x)
#define F7(x) F6(x),F6(x)
#define F8(x) F7(x),F7(x)
#define F9(x) F8(x),F8(x)
#define G1(x) F9(x),F9(x)
#define G2(x) G1(x),G1(x)
#define G3(x) G2(x),G2(x)
#define G4(x) G3(x),G3(x)
#define G5(x) G4(x),G4(x)
#define G6(x) G5(x),G5(x)
#define G7(x) G6(x),G6(x)
#define G8(x) G7(x),G7(x)
#define G9(x) G8(x),G8(x)

int main()
{
     G9(1);
}

当然,不同的编译器对预处理结果溢出的处理也不尽相同,一般上面的代码不会达到预期的目的。GCC会直接出错,而VC会出ICE(Internal Compiler Error)

2、Template

a、嵌套
类似的,模版也有嵌套层数限制,但是也很容易绕过。
GCC的某些版本就会被下面的代码搞挂(VC不会):

#include <cstddef>
template <class T>
struct Test {
     static const size_t Value=Test<Test<T> >::Value;
};

不过利用VC的某个bug(或者说特性),可以很容易的写出O(na)编译时间的模版:

#include <cstddef>

#define INNER(A3,N3,A2,N2) \
template<size_t N3>\

struct A3\
{\
     enum {N=A3<N3-1>::N+1};\
};\
template<>\

struct A3<0>\
{\
     enum {N=A2<N2-1>::N};\
};

#define OUTER(A2,N2,A1,N1,A3,CONTENT) \
template<size_t N2>\

struct A2\
{\
     CONTENT\
     \
     enum {N=A3<N2>::N};\
};\
template<>\

struct A2<0>\
{\
     enum {N=A1<N1-1>::N};\
};

#define LEVEL2(a,b,c) INNER(A##b,N##b,A##a,N##a)
#define LEVEL3(a,b,c) OUTER(A##b,N##b,A##a,N##a,A##c,LEVEL2(a##1,b##1,c##1))
#define LEVEL4(a,b,c) OUTER(A##b,N##b,A##a,N##a,A##c,LEVEL3(a##1,b##1,c##1))
#define LEVEL5(a,b,c) OUTER(A##b,N##b,A##a,N##a,A##c,LEVEL4(a##1,b##1,c##1))

 template<size_t N1>
struct A1
{
     LEVEL5(1,11,111)
    
enum {N=A11<N1>::N};
};

template<>
struct A1<0>
{
     enum {N=0};
};

这里比较有趣的一点是,标准并不允许这样在模版类里的特化。不知道这个算VC的bug呢还是扩展呢
A member or a member template may be nested within many enclosing class templates. In an explicit specialization for such a member, the member declaration shall be preceded by a template<> for each enclosing class template that is explicitly specialized
基于类似的思想,GCC&VC通用的版本也不难写出。

b、OLE
虽然通常模版的编译时间都是O(n)的,不过很多编译器的错误信息输出却是O(n2)的,利用这一点+很长的类名,很容易造成错误信息的Output Limit Exceed。比如:

#define ClassName A 
template <int N>
class ClassName
{
     enum {Value=ClassName<N-1>::Value};
};
int main()
{
     int n=ClassName<0>::Value;
}

如果我把ClassName改成某个很长的名称(现代的编译器都支持很长的变量名),那么错误输出就很容易OLE
PS:上面的代码在VC8里会直接出ICE,不过这是VC8的bug。VC2008没有这样的问题
posted @ 2007-11-02 18:08 shifan3 阅读(956) | 评论 (0)编辑 收藏
转载自神的blog
http://blog.csdn.net/vbvan/archive/2007/10/30/1857134.aspx

Flexible C++

C++是一门非常灵活的语言,只要充分发挥你的想象, 再普通的东西都能玩出新花样

1、1~1000求和
循环?递归?再简单不过的题目了。但是如果不允许你用判断语句呢?
如果你熟悉switch的内部实现,那么你很容易想到使用函数指针数组。

#include <cstdio>

typedef int (*fun)(int);
int f1(int i) {return 0;}
int f2(int i) {fun f[2]={f1,f2}; return i+f[!!i](i-1);}
int main()
{
     printf("%d\n",f2(1000));
}

2、输出1,2,...,100,99,...,2,1
如果同样不让你用判断语句呢?你仍然可以使用函数指针数组:

#include <cstdio>

typedef void (*fun)(int i,int n); 
void f1(int i,int n);
void f2(int i,int n);
void f3(int i,int n);

void f1(int i,int n)
{
     fun f[2]={f1,f2};

     printf("%d\n",i);
     f[i+1==n](i+1,n);
}

void f2(int i,int n)
{
     fun f[2]={f2,f3};
     printf("%d\n",i);
     f[i==1](i-1,n);
}

void f3(int i,int n) {}

int main()
{
     f1(1,100);
}

不过我们有更简洁的方法。
短路算法和逗号表达式粉墨登场了,一行搞定~

#include <cstdio>

void f(int i,int n)
{
     printf("%d\n",i),(i<n)&&(f(i+1,n),printf("%d\n",i));
}

int main()
{
     f(1,100);
}

posted @ 2007-11-02 18:05 shifan3 阅读(1332) | 评论 (3)编辑 收藏

江城子

黄叶满地秋已凉,豪气减,怨气长?
长子有感,我为毕业狂。
狂风逐叶又经年,白日短,愁日长?
长泪沾襟形容惭,顺者昌,逆者亡?
亡命玉泉,敢嗜血豺狼。
狼子野心不曾想:毕业难,就业黄?

by boylaugh
posted @ 2007-10-30 00:53 shifan3 阅读(984) | 评论 (2)编辑 收藏

发信人: xiaoheng (我的一班我的爱), 板面: C++
标  题: Re: 父类的方法能否使用子类的特有属性
发信站: 飘渺水云间 (Mon Aug 27 22:12:27 2007), 站内信件

我在公司只听说生女儿的,没有听说生儿子的。中国、印度、美国都一样。

【 在 shifan (Au revoir, mes amis) 的大作中提到: 】
: 应该说,老爸在没XX的时候,也无法决定后代是男是女
: 【 在 morningcs (BG5HLI·"鎏"金岁月·CS0306 Forever) 的大作中提到: 】
: : 你老爸在你小的时候也不知道你以后有啥特长

posted @ 2007-08-27 22:22 shifan3 阅读(1001) | 评论 (3)编辑 收藏
必先劳其筋骨

原来被开水烫是这个感觉。。。
posted @ 2007-08-26 21:38 shifan3 阅读(1035) | 评论 (3)编辑 收藏
材料 五花肉(或其他半肥瘦肉,网上众说纷纭-,-) 蒜苗

1。用水煮肉至肉熟皮软,捞出冷却切片
2。切蒜苗(菱形片)
3。豆丝(少许)、豆瓣(一勺或2勺)、甜酱(约一勺),盐(适量),混合后用油炒出香味
4。放入肉片,炒至发卷
5。放入蒜苗,炒熟后适量放味精等调料


ref http://news.xinhuanet.com/food/2004-09/14/content_1979737.htm
posted @ 2007-08-02 21:00 shifan3 阅读(1222) | 评论 (7)编辑 收藏
仅列出标题  下一页