lecture22-mar23 - Announcements Lecture 22 Welcome back...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Announcements Lecture 22 • Welcome back • Exam 2 moved to Friday, April 3 • Assignment 5 out today • Read Chapter 15 • Topics for today - Ch. 14 – What the Preprocessor Does –Mac ros – Conditional preprocessing Program Production Process C Compiler C object code (.obj) Executable Machine code Program (.exe) Load into RAM and execute C source file (.c) IDE C Preprocessor (handles file inclusion) C header files (.h) Linker many C library functions (.obj) Preprocessor Directives • Preprocessing involves making changes to the text of the source program (to save typing usually) • Preprocessing is done before compilation begins • The preprocessor doesn’t know (very much) C – It does however recognize C tokens • Major kinds of preprocessor directives: – Macro definition – Conditional compilation – File inclusion • Rules for using preprocessor directives: – Must begin with a #. – May contain extra spaces and tabs – Ends at the new-line character, unless continued using \ Can appear anywhere in a program – Comments may appear on the same line Simple Macros • Form of a simple macro: #define identifier replacement-list The replacement list can be any sequence of C tokens, including: identifiers, keywords, numbers, character constants, string literals, operators, and punctuation. • It causes a literal substitution of the replacement-list for all occurrences of the identifier later in the source program • Uses of simple macros: – Defining “symbolic constants” – Making minor changes to the syntax of C – Improving readability and modifiability – Alternate names for types – As conditions to be tested later by the preprocessor Preprocessor constants Define a symbolic constant like so #define PI 3.14159 Better version #define PI ( 3.14159 ) Use the symbolic constant in your program circle_length = 2 * PI * radius ; Other Examples • Examples of simple macros: #define N 100 #define NEWLINE '\n' #define WARNING "Warning: nonstandard \ feature" #define BEGIN_FCN { #define END_FCN } #define DEBUG
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/24/2010 for the course EE 312 taught by Professor Shafer during the Spring '08 term at University of Texas at Austin.

Page1 / 4

lecture22-mar23 - Announcements Lecture 22 Welcome back...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online