Lecture Introduction to Computer Programming - Lecture 15

This chapter examines some more advanced concepts related to process management, which are found in a number of contemporary operating systems. We show that the concept of process is more complex and subtle than presented so far and in fact embodies two separate and potentially independent concepts: one relating to resource ownership and another relating to execution. | CSC141- Introduction to Computer Programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture – 15 Preprocessor Directives A program that processes the source code before passing it to the compiler. Preprocessor commands (known as directives) can be considered a language within C language. We can write C programs even without knowing anything about the preprocessor or its facilities. 6/5/2012 3 Preprocessor Directives Function of utilities 6/5/2012 4 The preprocessor offers several features called preprocessor directives. Each directive begin with a # symbol. The directives can be placed anywhere in a program but are mostly placed at the beginning of a program and before the first function definition. Categories of these directives are: (a) Macro expansion #define (b) File inclusion # include (c) Conditional Compilation #if, #elif (d) Miscellaneous #undef 6/5/2012 5 Preprocessor Directives # define directive used for macro expansion Example-1: #define UPPER 25 main( ) { int i ; for ( i = 1 ; i <= UPPER ; i++ ) printf ( "\n%d", i ) ; } 6/5/2012 6 Instead of writing 25 in the for loop we have defined a constantan before the start of the definition of main( ) function. #define UPPER 25 This above statement is called ‘macro definition’ or more commonly, just a ‘macro’. During preprocessing, the preprocessor replaces every occurrence of UPPER in the program with 25. 6/5/2012 7 Explanation Macro Expansion Example - 2: #define PI main( ) { float r = ; float area ; area = PI * r * r ; printf ( "\nArea of circle = %f", area ) ; } Output: Area of circle = 6/5/2012 8 Macro Expansion UPPER and PI in the above programs are often called ‘macro templates’, whereas, 25 and are called their corresponding ‘macro expansions’. When we compile the program, before the source code passes to the compiler it is examined by the C preprocessor for any macro definitions. When it sees the #define directive, it goes through the entire program in search of the macro . | CSC141- Introduction to Computer Programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture – 15 Preprocessor Directives A program that processes the source code before passing it to the compiler. Preprocessor commands (known as directives) can be considered a language within C language. We can write C programs even without knowing anything about the preprocessor or its facilities. 6/5/2012 3 Preprocessor Directives Function of utilities 6/5/2012 4 The preprocessor offers several features called preprocessor directives. Each directive begin with a # symbol. The directives can be placed anywhere in a program but are mostly placed at the beginning of a program and before the first function definition. Categories of these directives are: (a) Macro expansion #define (b) File inclusion # include (c) Conditional Compilation #if, #elif (d) Miscellaneous #undef 6/5/2012 5 Preprocessor Directives # define directive used for macro expansion Example-1: #define UPPER 25 main( ) { int i ; for ( i = 1 ; i

Bấm vào đây để xem trước nội dung
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.