Mathematics 1201: Programming in C Solutions to Reading and Homework Assignment #5 Prof. Wickerhauser Chapter 5 Exercises: Exercise 3, p.118: The ``assert'' macro is defined in , which on UNIX systems such as ArtSci means the file ``/usr/include/assert.h''. Check there for a somewhat complicated solution of this problem. Another solution is #ifdef NDEBUG #define assert(expr) (0) #else #define assert(expr) \ if( !(expr) ) { \ printf("%s false in file %s, line %d\n", \ #expr, __FILE__, __LINE__ ); \ exit(1); } #endif Exercise 12, p.119: #define IsLeap(Year) ( (Year)%400==0 || ( (Year)%100!=0 && (Year)%4==0) ) Extra Problem: The macros expand in the following sequence: START --> main(void){ Join(P,N) --> PN --> printf( Stringize(__LINE__) --> "__LINE__" STUFF --> "= %d\n" COMMA --> , __LINE__ --> 16 FINISH --> );} The compiler ignores white space and combines these into main(void){printf("__LINE__""= %d\n",16);} The string constants "__LINE__" and "= %d\n" are then concatenated into a single string, resulting in the valid ANSI C program main(void){printf("__LINE__= %d\n",16);} which prints out the message __LINE__= 16