lecture22-mar12 - Announcements Lecture 22 No recitations...

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

View Full Document Right Arrow Icon
1 Announcements Lecture 22 • No recitations today • Assignment 4 – write down your stats • Assignment 5 – comes out after spring break • Topics for today - Ch. 14 – Finish enums – What the Preprocessor Does • It’s just a fancy text manipulator – Macros ( #define directives) – Conditional preprocessing enum Type An enumeration type stands for a small set of named integer constants that specify all the legal values that a variable of that type can hold. C treats enum values as integers Declared with the enum tag, E.g. enum weekday { SUN, MON, TUE, WED, THURS, FRI, SAT }; /* C gives these the values of 0,1,2,. . . 6 by default */ . . . enum weekday today; /* declare a variable of that type */ scanf (“ %d ”, &today); if ( today == MON | | today == WED || today == FRI ) { printf ( "Today is a ee312 lecture day;go to class \n"); } typedef enum {FALSE, TRUE} Bool; /* a boolean data type */ Enumerations - example 2 /* you can give the identifiers specific int values instead */ enum coin_value { PENNY=1, NICKEL=5, DIME=10, QUARTER=25, HALF_DOLLAR=50, DOLLAR=100}; enum coin_value money ; /* declare a variable of that type*/ scanf (“%d”, &money); printf ( ”the value of money input is a ”); switch(money) { case PENNY: printf ( "penny”); break; case NICKEL: printf ( "nickel”); break; case DIME: printf ( "dime”); break; case QUARTER: printf ( "quarter”); break; case HALF_DOLLAR: printf ( "half_dollar”); break; case DOLLAR: printf ( "dollar”); break; default: printf ( ” non-legitimate coin value”); /* possible */ } Program Production Process C Compiler C object code (.obj) Executable Machine code Program (.exe) Load into RAM and execute C source file (.c) IDE (VS) C Preprocessor (handles # directives) C header files (.h) Linker many C library functions (.obj) How the Preprocessor Works • The preprocessor’s role in the compilation process: Deletes all comments and unnecessary white space Handles all # directives Preprocessor Directives • Preprocessing involves making changes to the
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.

Page1 / 3

lecture22-mar12 - Announcements Lecture 22 No recitations...

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