Expert C Programming

(Jeff_L) #1

fprintf(f,I))t('O',4,"r",while(fgets(B,R,f))(*Q(B,"\n")=0,G())


)X 0:default:G()


;}_ 0;}G(){l=atoi(B);m[l]&&free(m[l]);(p=Q(B,"


"))?strcpy(m[l]=malloc(strlen(p


)),p+1):(m[l]=0,0);}O(S,J,'=',==,'#',!=)O(J,K,'<',<,'>',>)O(K,


V,'$',<=,'!',>=)


O(V,W,'+',+,'-',-)O(W,Y,'',,'/',/)Y(){int o;_*p=='-'?p++,-


Y():p>='0'&&p<=


'9'?strtol(p,&p,0):p=='('?p++,o=S(),p++,o:P[p++];}


Watch for the difference between the letter "l" and the digit "1" when you type this in! If it's on the
left-hand side of an assignment, it must be the letter "l".


This is an incredible program, and it's well worth reverse-engineering it to remove the obfuscation and
see how it works. If this fires your imagination, you'll be pleased to hear that you too can enter the
IOCCC. Just read the comp.lang.c newsgroup on Usenet and follow the instructions posted there in
late Autumn. Be warned that the winners are among the best programmers in the world, and they're
doing their worst.


Programming Solution


Type Promotion Mix-Up in Prototypes


main() {


union {


double d;


float f;


}u;


u.d = 10.0;


printf(" put in a double, pull out a float f= %f


\n", u.f);


u.f=10.0;


printf(" put in a float, pull out a double d= %f


\n", u.d);


}


%a.out


put in a double, pull out a float f= 2.562500


put in a float, pull out a double d= 524288.000000

Free download pdf