1 / 27

C 的命运交响曲

C 的命运交响曲. 孙志岗. 偶系 凉粉 也系 稀饭!. C 的命运交响曲. 第一乐章: 宿命 第二乐章: 乐趣 第三乐章: 前途. C 的命运交响曲. 第一章: 宿命 第二章: 乐趣 第三章: 前途. 宿命. C 必须服从的关键文档 ISO/IEC 9899:1999 (C99) C 的生命绝唱 C05 即将推出,但只是 bugfix 解释 C 标准的文档 Rationale for International Standard Programming Language C ( V5.1 ). 判词 ——Spirit of C.

keene
Download Presentation

C 的命运交响曲

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. C的命运交响曲 孙志岗

  2. 偶系凉粉 也系稀饭!

  3. C的命运交响曲 • 第一乐章:宿命 • 第二乐章:乐趣 • 第三乐章:前途

  4. C的命运交响曲 • 第一章:宿命 • 第二章:乐趣 • 第三章:前途

  5. 宿命 • C必须服从的关键文档 • ISO/IEC 9899:1999 (C99) • C的生命绝唱 • C05即将推出,但只是bugfix • 解释C标准的文档 • Rationale for International Standard Programming Language C (V5.1)

  6. 判词——Spirit of C • Trust the programmer. • Don’t prevent the programmer from doing what needs to be done. • Keep the language small and simple. • Provide only one way to do an operation. • Make it fast, even if it is not guaranteed to be portable. ——from Rationale for C99

  7. 判词——C的精神 • 信任程序员。 • 不要阻止程序员做他认为应该做的事。 • 保持语言的精巧和简单。 • 对一种操作只提供一种方法。 • 一定要快,哪怕这么做是不可移植的。 ——引自《Rationale for C99》

  8. C的祖师爷——Dennis M. Ritchie http://www.cs.bell-labs.com/who/dmr/

  9. Ritchie said C is quirky, flawed, and an enormous success. C诡异离奇、缺陷重重,却获得巨大成功

  10. Ritchie和Thompson在玩游戏

  11. 游戏创世纪 • 引子——一个游戏 • Space Travel • http://cm.bell-labs.com/cm/cs/who/dmr/spacetravel.html • 结果——两部巨著 • UNIX • C • 成就——两个超级黑客 • Ritchie & Thompson • 1983,图灵奖

  12. C的命运交响曲 • 第一章:宿命 • 第二章:乐趣 • 第三章:前途

  13. 趣味程序1——平方根(Raymond Cheong ) #include <stdio.h> int l;int main(int o,char **O, int I){char c,*D=O[1];if(o>0){ for(l=0;D[l ];D[l ++]-=10){D [l++]-=120;D[l]-= 110;while (!main(0,O,l))D[l] += 20; putchar((D[l]+1032) /20 ) ;}putchar(10);}else{ c=o+ (D[I]+82)%10-(I>l/2)* (D[I-l+I]+72)/10-9;D[I]+=I<0?0 :!(o=main(c/10,O,I-1))*((c+999 )%10-(D[I]+92)%10);}return o;}

  14. 趣味程序2——旗语(Glyn Anderson) #include <stdio.h> char *T="IeJKLMaYQCE]jbZRskc[SldU^V\\X\\|/_<[<:90!\"$434-./2>]s", K[3][1000],*F,x,A,*M[2],*J,r[4],*g,N,Y,*Q,W,*k,q,D;X(){r [r [r[3]=M[1-(x&1)][*r=W,1],2]=*Q+2,1]=x+1+Y,*g++=((((x& 7) -1)>>1)-1)?*r:r[x>>3],(++x<*r)&&X();}E(){A||X(x=0,g =J ),x=7&(*T>>A*3),J[(x[F]-W-x)^A*7]=Q[x&3]^A*(*M)[2 +( x&1)],g=J+((x[k]-W)^A*7)-A,g[1]=(*M)[*g=M[T+=A ,1 ][x&1],x&1],(A^=1)&&(E(),J+=W);}l(){E(--q&&l () );}B(){*J&&B((D=*J,Q[2]<D&&D<k[1]&&(*g++=1 ), !(D-W&&D-9&&D-10&&D-13)&&(!*r&&(*g++=0) ,* r=1)||64<D&&D<91&&(*r=0,*g++=D-63)||D >= 97&&D<123&&(*r=0,*g++=D-95)||!(D-k[ 3] )&&(*r=0,*g++=12)||D>k[3]&&D<=k[ 1] -1&&(*r=0,*g++=D-47),J++));}j( ){ putchar(A);}b(){(j(A=(*K)[D* W+ r[2]*Y+x]),++x<Y)&&b();}t () {(j((b(D=q[g],x=0),A=W) ), ++q<(*(r+1)<Y?*(r+1): Y) )&&t();}R(){(A=(t( q= 0),'\n'),j(),++r [2 ]<N)&&R();}O() {( j((r[2]=0,R( )) ),r[1]-=q) && O(g-=-q) ;} C(){( J= gets (K [1]))&&C((B(g=K[2]),*r=!(!*r&&(*g++=0)),(*r)[r]=g-K[2],g=K[2 ],r[ 1]&& O()) );;} main (){C ((l( (J=( A=0) [K], A[M] =(F= (k=( M[!A ]=(Q =T+( q=(Y =(W= 32)- (N=4 )))) +N)+ 2)+7 )+7) ),Y= N<<( *r=! -A)) );;}

  15. 趣味程序3——一元n次方程图(Jonathan Hoyle) #include <stdio.h> #include <stdlib.h> #include <math.h> #define _ ;double #define void x,x #define case(break,default) break[O]:default[O]: #define switch(bool) ;for(;x<bool; #define do(if,else) inIine(else)>int##if? #define true (--void++) #define false (++void--) char*O=" <60>!?\\\n"_ doubIe[010]_ int0,int1 _ Iong=0 _ inIine(int eIse){int O1O=!O _ l=!O;for(;O1O<010;++O1O)l+=(O1O[doubIe]*pow(eIse,O1O));return l;}int main(int booI,char*eIse[]){int I=1,x=-*O;if(eIse){for(;I<010+1;I++)I[doubIe-1] =booI>I?atof(I[eIse]):!O switch(*O)x++)abs(inIine(x))>Iong&&(Iong=abs(inIine(x )));int1=Iong;main(-*O>>1,0);}else{if(booI<*O>>1){int0=int1;int1=int0-2*Iong/0 [O]switch(5[O]))putchar(x-*O?(int0>=inIine(x)&&do(1,x)do(0,true)do(0,false) case(2,1)do(1,true)do(0,false)6[O]case(-3,6)do(0,false)6[O]-3[O]:do(1,false) case(5,4)x?booI?0:6[O]:7[O])+*O:8[O]),x++;main(++booI,0);}}}

  16. 趣味程序4——迷宫(Nick Johnson) #include <ncurses.h>/*****************************************************/ int m[256 ] [ 256 ],a ,b ;;; ;;; WINDOW*w; char*l="" "\176qxl" "q" "q" "k" "w\ xm" "x" "t" "j" "v" "u" "n" ,Q[ ]= "Z" "pt!ftd`" "qdc!`eu" "dq!$c!nnwf"/** *** */"t\040\t";c( int u , int v){ v?m [u] [v- 1] |=2,m[u][v-1] & 48?W][v-1 ] & 15]]):0:0;u?m[u -1][v]|=1 ,m[ u- 1][ v]& 48? W-1 ][v ]& 15] ]):0:0;v< 255 ?m[ u][v+1]|=8,m[u][v+1]& 48? W][ v+1]&15]] ):0 :0; u < 255 ?m[ u+1 ][v ]|= 4,m[u+1][ v]&48?W+1][v]&15]]):0:0;W][ v]& 15] ]);}cu(char*q){ return *q ?cu (q+ 1)& 1?q [0] ++: q[0 ]-- :1; }d( int u , int/**/v, int/**/x, int y){ int Y=y -v, X=x -u; int S,s ;Y< 0?Y =-Y ,s, s=- 1:( s=1);X<0?X=-X,S =-1 :(S= 1); Y<<= 1;X<<=1; if(X>Y){ int f=Y -(X >>1 );; while(u!= x){ f>= 0?v+=s,f-=X:0;u +=S ;f+= Y;m[u][v]|=32;mvwaddch(w,v ,u, m[u ][ v]& 64? 60: 46) ;if (m[ u][ v]&16){c(u,v);; ;;; ;;; return;}} }else{int f=X -(Y>>1);; while (v !=y ){f >=0 ?u +=S, f-= Y:0 ;v +=s ;f+=X;m[u][v]|= 32;mvwaddch(w,v ,u,m[u][v]&64?60:46);if(m[u ][ v]& 16) {c( u,v ); ; return;;;}}}}Z( int/**/a, int b){ }e( int/**/y,int/**/ x){ int i ; for (i= a;i <=a +S;i++)d(y,x,i,b),d(y,x,i,b+L);for(i=b;i<=b+L;i++)d(y,x,a,i),d(y,x,a+ S,i ); ;;; ;;; ;;; ;;; ; mvwaddch(w,x,y,64); ;;; ;;; ;;; prefresh( w,b,a,0,0 ,L- 1,S-1 );} main( int V , char *C[ ] ){FILE*f= fopen(V==1?"arachnid.c"/**/ :C[ 1],"r");int/**/x,y,c, v=0 ;;; initscr (); Z(Z (raw () ,Z( curs_set(0),Z(1 ,noecho()))),keypad( stdscr,TRUE));w =newpad ( 300, 300 ) ; for (x= 255 ; x >=0 ;x-- ) for (y= 255 ;y>=0;y-- )m[ x][ y]= 0;x=y=0;refresh( );while ( (c= fgetc (f) )+1) {if( 0||c==10|| x== 256){x=0;y++;if(y==256 )break;;} else{m[x][y]=(c == '~' ?64 : c ==32 ?0: 16) ;;x ++; }}for(x=0 ;x< 256;x++)m [x][0]=16 ,m[ x][ 255]=16;for(y=0 ;y< 256 ; y ++) m[0 ][y ] = 16, m[255][y] =16 ;a=b=c=0; x=y =1; do{v++;mvwaddch (w, y,x ,m[ x][ y]& 32? m[x ][y ] & 16? 0| acs_map[l[m[x][y]&15]]:46 : 32);c==0163&&!(m[x][y+1]&16)?y++: 0;c == 119 &&! (m[ x][ y- 1]& 16) ?y--:0;;c ==97 &&!(m[x-1][y]&16)?x--:0;c==100&&!(m[x+1 ][ y]& 16) ? x ++:0 ;if( c== 3- 1+1 ){endwin( );; return(0) ;}x -a<5?a>S- 5?a-=S-5:(a=0): 0;x -a> S-5?a<255 -S* 2?a +=S -5:(a=256-S):0; y-b<5?b>L-5?b-=L-5:(b =0) :0; y-b>L-5?b<255-L *2? b+= L-5 :(b =256 -L) :0;e(x,y);if(m[x][y]&64)break;}while((c=getch())!=-1);endwin();cu(Q); printf(Q,v);}

  17. 趣味程序5——文字加密(Sunner Sun) int main(void){char p[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.\ 0123456789"; char *q="tDJA3SfoP"; int i=sizeof p,l;char *strchr ();int putchar ();while (*q){ putchar(p[i=(i^ (l= strchr(p,*q++)-p))&0x3F ]);i=l>i?l:i;}return 0;} http://sunner.cn

  18. 外星程序1——PI int a=10000,b,c=2800,d,e,f[2801],g; main() { for(;b-c;) f[b++]=a/5; for(;d=0,g=c*2;c -=14,printf("%.4d",e+d/a),e=d%a) for(b=c; d+=f[b]*a,f[b]=d%--g,d/=g--,--b; d*=b); }

  19. 外星程序2——Duff's device send(to, from, count) register short *to, *from; register count; { register n=(count+7)/8; switch(count%8){ case 0: do{ *to = *from++; case 7: *to = *from++; case 6: *to = *from++; case 5: *to = *from++; case 4: *to = *from++; case 3: *to = *from++; case 2: *to = *from++; case 1: *to = *from++; }while(--n>0); } }

  20. C的命运交响曲 • 第一章:宿命 • 第二章:乐趣 • 第三章:前途

  21. 存在最好的语言吗? • Match is best!适合的才是最好的 • 做不同的事情,用不同的语言;不知道自己将来会做什么事;所以,不知道会用到什么语言。 • 我会一种语言;找适合此语言的事情做;不知道此语言能活多久。 • 学什么语言并不是最重要的

  22. C语言是基础吗? • C语言不是学编程的基础 • C语言是计算机的基础 • 最重要的软件,几乎都是C编的 • 非C的语言,几乎都是直接或间接用C开发的,C++除外 C

  23. C适合做什么事情? • C什么事情都可以做 • 受限环境和底层环境 • 对速度和内存消耗有苛刻要求 • 需要更直接地与硬件交互 • 系统级软件:操作系统等 • 嵌入式系统 • 不适合做大型、复杂、面向应用的系统

  24. 稀饭都是什么样的人? • 骨灰级程序员 • 黑客 • 不是媒体所言“黑客” • 喜欢刨根问底 • 向往自由 • 乐于共享

  25. 语言受欢迎的程度 http://www.tiobe.com/tpci.htm

  26. If you've just spent nearly 30 hours Debugging some assembly, Soon you will be glad to Write in C. Write in C, Write in C, Write in C, yeah, Write in C. Only wimps use BASIC. Write in C. Write in C, Write in C Write in C, oh, Write in C. Pascal won't quite cut it. Write in C. Write in C, Write in C, Write in C, yeah, Write in C. Don't even mention COBOL. Write in C. When I find my code in tons of trouble, Friends and colleagues come to me, Speaking words of wisdom: "Write in C." As the deadline fast approaches, And bugs are all that I can see, Somewhere, someone whispers: "Write in C." Write in C, Write in C, Write in C, oh, Write in C. LOGO's dead and buried, Write in C. I used to write a lot of FORTRAN, For science it worked flawlessly. Try using it for graphics! Write in C. Write in C

  27. C Develops Endless Future http://wiki.hit.edu.cn/index.php/C_Develops_Endless_Future 谢谢!

More Related