我见过的最疯狂的C代码

jopen 10年前

        Quora 原文:What are some of the most amazing C programs?

        C 语言是最强大的语言之一。但是到底它的强大表现在何处?写操作系统?Too young to naive!

        Quora 上众多程序员分享了自己见过的最令人惊叹的C语言代码。敲代码敲累了?看一些养眼的代码休息一下吧!

        1. 如何优雅地写一封信

        下面是 Brian Westley aka Merlyn LeRoy 写的一段C程序。但如果细读起来你会发现它是 Charlie 和 Charlotte 两人之间的书信!

        注:这段代码还能编译运行!

char*lie;  double time, me= !0XFACE,   not; int rested, get, out;  main (ly, die) char ly, **die ;{  signed char lotte,     dear; (char) lotte--;  for(get= !me;; not){  1s - out & out ;lie;{  char lotte, my= dear,  **let= !!me *!not+ ++die;  (char*)(lie= "The gloves are OFF this time, I detest you, snot\n\0sed GEEK!");  do {not= *lie++ & 0xF00L* !me;  #define love (char*) lie -  love 1s *!(not= atoi (let  [get -me?  (char) lotte-  (char) lotte: my- *love - 'I' - *love - 'U' - 'I' - (long) - 4 - 'U' ])- !!  (time =out= 'a'));} while( my - dear  && 'I'-1l -get- 'a'); break;}}  (char)*lie++;   (char)*lie++, (char)*lie++; hell:0, (char)*lie;  get *out* (short) ly -0-'R'- get- 'a'^rested;  do {auto*eroticism,  that; puts (*( out - 'c' -('P'-'S') +die+ -2 ));}while(!"you're at it");  for (*((char*)&lotte)^=  (char) lotte; (love ly) [(char)++lotte+ !!0xBABE];){ if ('I' -lie[ 2 + (char) lotte]){ 'I'-1l ***die; }  else{ if ('I' * get *out* ('I'-1l **die[ 2 ])) *((char*)&lotte) -= '4' - ('I'-1l); not; for(get=! get; !out;   (char)*lie & 0xD0- !not) return!!  (char) lotte;}     (char) lotte;    do{ not* putchar (lie [out *!not* !!me + (char) lotte]);     not; for(;!'a';);}while(  love (char*) lie);{      register this; switch( (char) lie     [(char) lotte] -1s *!out) {  char*les, get= 0xFF, my; case' ':    *((char*)&lotte) += 15; !not + (char)*lie*'s';  this +1s+ not; default: 0xF + (char*) lie;}}}   get - !out;     if (not--)  goto hell;     exit ( (char) lotte);}

        Copyright (c) 1990, Landon Curt Noll & Larry Bassel. All Rights Reserved. Permission for personal, educational or non-profit use is granted provided this this copyright and notice are included in its entirety and remains unaltered. All other uses must receive prior permission in writing from both Landon Curt Noll and Larry Bassel.

        2. 分分钟画一幅地图

        这一小段貌不惊人的代码竟然能画出印度地图!!

  main ()  {  int a,b,c;  int count = 1;     for (b = c = 10;  a = "- FIGURE?, UMKC,XYZHello Folks,\ TFy!QJu ROo TNn (ROo) SLq SLq ULo+\  UHs UJq TNn*RPn/QPbEWS_JSWQAIJO^\  NBELPeHBFHT}TnALVlBLOFAkHFOuFETp\  HCStHAUFAgcEAelclcn^r^r\\tZvYxXy\  T|S~Pn SPm SOn TNn ULo0ULo#ULo-W\  Hq!WFs XDt!"[b+++21]; ) for(; a-- > 64 ; )  putchar ( ++c=='Z' ? c = c/ 9:33^b&1);     return 0;  }

 我见过的最疯狂的C代码

https://gist.githubusercontent.com/Jing0/903584da1060897a7e43/raw/india-map-written-by-c

        3. 自己输出自己的代码

 main () {      char q=34,      n=10,*a="main () { char q=34,          n=10,          *a=%c%s%c;          printf (a,q,a,q,n);      }%c";       printf (a,q,a,q,n);  }     

        看着这段代码,想起了Tupper 自我指涉公式

        One More Thing

        国际上还有个专门的比赛 IOCCC-The International Obfuscated C Code Contest,评选那些最奇怪最疯狂最有创意的C语言代码,到去年已经举办 22 届了。这些代码有的是图画,有的输出一些奇怪的东西,当然,它们都能完美地运行!

        程序员玩起来创意,是谁也比不过的!

来自: jackiekuo.com