颜林林的个人网站

Linlin Yan's Personal Website

分享搞笑代码

2007-10-01 21:22

过去看《More Exceptional C++》等书时,发现总会提到 comp.lang.c++ 的新闻组,曾经有段时间用 Outlook Express 去浏览,但总觉使用起来不方便。这两天无意之间发现google居然提供了能够直接通过网页去访问它的方法。推荐一下:

http://groups.google.com/group/comp.lang.c++

(其他新闻组也可以通过类似的方式访问到)

发现这个网页的那天,心情兴奋地仔细看了十几个主题(我英文不好,看得慢),有些比较有趣的话题,所以即使第二天要上班,还是忍不住看到了四点多才睡觉。其中竟然有人问“How to write spaghetti code in C++??? ”(如何用C++写出意大利面条式的代码),那人说自己用了20多年的Basic而现在被迫升级到C++因此很烦恼,结果有强人贴上了这么段代码:

#define GOTO( n ) { label = n; goto dispatch; }

int main()
{
    int label = 100;
    int const taxCoefficient = 5;
    dispatch:
    switch( label )
    {
        100: { GOTO( 160 ); }
        110: {} // Nothing to see here, move on, move on!
        120: { return; }
        130: { GOTO( 1000*taxCoefficient ); }
        140: {} // Nothing to see here, move on, move on!
        150: {} // Nothing to see here, move on, move on!
        160: { GOTO( 130 );
        5000: { GOTO 120; }
    }
}