CS201-23 - Introduction to Programming Lecture 23...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Introduction to Programming Lecture 23 Preprocessors and Header files Today’s Lecture Preprocessor Directives Header Files Macros Preprocessor #include <iostream.h> # #include #include <iostream.h> #include <stdlib.h> #include <fstream.h> #include <stream.h> 5:10 to 5:23 5:24 to 5:41 Re­locatable Executable MyHeader.h #include “MyHeader.h” #include <iostream.h> #define #define PI 3.141592 Preprocessor Directives #if #else #endif #elif #ifdef #ifndef #error Preprocessor Directives #ident #import #line #machine #system #warning Example #ifdef PI # define PI # ifdef PI # define DEBUG # ifdef DEBUG Conditional Compilation Macro Translation #undef DEBUG #include <conio.h> Consol Input Output #include <conio.h> #include <conio.c> int getche ( ) ; Get Character With Echo #ifdef __cplusplus extern "C" { #endif ­ ­ ­ ­ #ifdef __cplusplus } #endif Macro #define SQUARE ( X ) X * X main ( ) { int i = 5 , j ; : j = i * i ; SQUARE ( i ) ; } Example 1 #define SQUARE ( X ) X * X main ( ) { int i = 5 , j = 10 , k ; : i + j * i + j ; k = SQUARE ( i + j ) ; } Example 2 #define SQUARE(X) (X)*(X) main ( ) { int i = 5 , j = 10 , k ; ( i + j ) * ( i + j ) ; k = SQUARE ( i + j ) ; } Example 3 Overhead Code Bloat #define PI 3.14159 #define CIRCLEAREA ( X )PI * X * X ( ( PI ) * ( X ) * ( X ) ) main ( ) { float radius ; cout << “ Enter radius of Circle Area : ” ; cin >> radius ; cout << “ Area of Circle Area is ” ( ( PI ) * ( radius ) * ( radius ) ) ; CIRCLEAREA ( 2 * radius ) ; << CIRCLEAREA ( radius ) ; } Example 4 Header Files Header File #include <iostream.h> #include <stdlib.h> #include <stdio.h> #include <string.h> In Next Lecture Memory Allocation ...
View Full Document

This note was uploaded on 01/12/2010 for the course CS CS 201 taught by Professor Dr.naveedmalik during the Spring '09 term at Virtual University of Pakistan.

Ask a homework question - tutors are online