tailieunhanh - Lecture Introduction to Computer Programming - Lecture 16

The contents of this chapter include all of the following: Discuss basic concepts related to concurrency, such as race conditions, OS concerns, and mutual exclusion requirements; understand hardware approaches to supporting mutual exclusion; define and explain semaphores; define and explain monitors. | CSC141- Introduction to Computer programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture – 16 Thanks for Lecture Slides: Dr. Sadaf Tanveer, Assistant Professor, CIIT 1 Continuation of previous Lecture Preprocessor Directives #if and #elif Directives The #if directive can be used to test whether an expression evaluates to a nonzero value or not. If the result of the expression is nonzero, then subsequent lines upto a #else, #elif or #endif are compiled, otherwise they are skipped. A simple example of #if directive is shown below: main( ) { #if TEST <= 5 statement 1 ; statement 2 ; statement 3 ; #else statement 4 ; statement 5 ; statement 6 ; #endif } 6/5/2012 3 If the expression, TEST <= 5 evaluates to true then statements 1, 2 and 3 are compiled otherwise statements 4, 5 and 6 are compiled. In place of the expression TEST <= 5 other expressions like ( LEVEL == HIGH || LEVEL == LOW ) or ADAPTER == CGA can also be used. If we want, we can have nested conditional compilation directives. An example that uses such directives is shown below. #if ADAPTER == VGA code for video graphics array #else #if ADAPTER == SVGA code for super video graphics array #else code for extended graphics adapter #endif #endif 6/5/2012 4 Explanation The above program segment can be made more compact by using another conditional compilation directive called #elif. The same program using this directive can be rewritten as shown below. Observe that by using the #elif directives the number of #endifs used in the program get reduced. #if ADAPTER == VGA code for video graphics array #elif ADAPTER == SVGA code for super video graphics array #else code for extended graphics adapter #endif 6/5/2012 5 #elif directive Explanation Miscellaneous Directives There are two more preprocessor directives available, though they are not very commonly used. They are: (a) #undef (b) #pragma #undef Directive On some occasions it may be desirable to cause a defined name to become ‘undefined’. This can be accomplished by . | CSC141- Introduction to Computer programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture – 16 Thanks for Lecture Slides: Dr. Sadaf Tanveer, Assistant Professor, CIIT 1 Continuation of previous Lecture Preprocessor Directives #if and #elif Directives The #if directive can be used to test whether an expression evaluates to a nonzero value or not. If the result of the expression is nonzero, then subsequent lines upto a #else, #elif or #endif are compiled, otherwise they are skipped. A simple example of #if directive is shown below: main( ) { #if TEST <= 5 statement 1 ; statement 2 ; statement 3 ; #else statement 4 ; statement 5 ; statement 6 ; #endif } 6/5/2012 3 If the expression, TEST <= 5 evaluates to true then statements 1, 2 and 3 are compiled otherwise statements 4, 5 and 6 are compiled. In place of the expression TEST <= 5 other expressions like ( LEVEL == HIGH || LEVEL == LOW ) or ADAPTER == CGA can also be used. If we want, we can have nested conditional compilation directives. An .

TỪ KHÓA LIÊN QUAN