我見過的最瘋狂的C代碼

jopen 10年前發布 | 8K 次閱讀 C代碼

        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 {autoeroticism, 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) { charles, 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);}</pre>

        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; }</pre>

 我見過的最瘋狂的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

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!