混乱过的 C 语言 Hello World 程序

February 20, 2008 – 10:30 am

相信不少人都听说过国际 C 语言混乱大赛吧?里面有不少看起来千奇百怪的代码,但却都是完整的 C 程序并且不少是非常有用并且高效的程序。今天我在这里又看到几个混乱过的 Hello World 程序,例如:

#define _________ }
#define ________ putchar
#define _______ main
#define _(a) ________(a);
#define ______ _______(){
#define __ ______ _(0x48)_(0x65)_(0x6C)_(0x6C)
#define ___ _(0x6F)_(0x2C)_(0x20)_(0x77)_(0x6F)
#define ____ _(0x72)_(0x6C)_(0x64)_(0x21)
#define _____ __ ___ ____ _________
#include<stdio.h>
_____

如果我不说,你能看出来它是一个打印 Hello World 的程序吗?还有这个(据说只能用 C++ 编译器编译)看起来是不是有点 Brainfuck 语言的味道?

#include <stdio.h>
#define _(_) putchar(_);
int main(void){int i = 0;_(
++++++++++++++++++++++++++++
++++++++++++++++++++++++++++
++++++++++++++++++++++++++++
++++++++++++++++++++++++++++
++++++++++++++++++++++++++++
++++i)_(++++++++++++++++++++
++++++++++++++++++++++++++++
++++++++++i)_(++++++++++++++
i)_(--++i)_(++++++i)_(------
----------------------------
----------------------------
----------------------------
----------------------------
----------------i)_(--------
----------------i)_(++++++++
++++++++++++++++++++++++++++
++++++++++++++++++++++++++++
++++++++++++++++++++++++++++
++++++++++++++++++++++++++++
++++++++++++++++++++++++++++
++++++++++++++++++++++++++i)
_(----------------i)_(++++++
i)_(------------i)_(--------
--------i)_(----------------
----------------------------
----------------------------
----------------------------
----------------------------
------i)_(------------------
----------------------------
i)return i;}

这个网站上还列举了不少这类似的程序,自己去看看吧! :)

  1. 2 Responses to “混乱过的 C 语言 Hello World 程序”

  2. Blog变得简洁起来~

    自己在写wmii那篇的时候也是,想想有许多东西可以介绍,最后都省略了…

    也许这就是传说中的“深入浅出”吧,我也非常喜欢这样的风格~

    By quark on Feb 21, 2008

  3. 晕,这些人真能玩 :)

    By Pink on Mar 5, 2008

Post a Comment