Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lab guide # 12 Review C Preprocessor And Q&A.

Similar presentations


Presentation on theme: "Lab guide # 12 Review C Preprocessor And Q&A."— Presentation transcript:

1 Lab guide # 12 Review C Preprocessor And Q&A

2 Key points #include Preprocessor Directive
#define Preprocessor Directive: Symbolic Constants #define Preprocessor Directive: Macros #error and #pragma Preprocessor Directives # and ## Operators Line Numbers Predefined Symbolic Constants Assertions

3 For example in “constants.h” we have
#ifndef _CONSTANT_ #define _CONSTANT_ #define pi #define h e /* Planck's constant/2PI in J-sec */ #define am e /* Electron rest mass in kg */ #define q e /* Electron charge */ #define kb e /* Boltzmann constant J/Kelvin */ #define eps_ e /* Permittivity of free space. unit F/m */ #define max_electron_number #endif //_CONSTANT_

4 Macro Operation defined in #define
A macro without arguments is treated like a symbolic constant A macro with arguments has its arguments substituted for replacement text, when the macro is expanded Performs a text substitution – no data type checking The macro #define CIRCLE_AREA( x ) ( PI * ( x ) * ( x ) ) would cause area = CIRCLE_AREA( 4 ); to become area = ( * ( 4 ) * ( 4 ) );

5 Assertions assert macro Header <assert.h>
Tests value of an expression If 0 (false) prints error message and calls abort Example: assert( x <= 10 ); If NDEBUG is defined All subsequent assert statements ignored #define NDEBUG

6 Review chapter 7-12 for Final Exam
C pointers C characters and Strings C formatted Input/Output C Structures, Unions, Bit manipulations and Enumerations C File processing C Data structures

7 Q&A About HW and Lab assignments


Download ppt "Lab guide # 12 Review C Preprocessor And Q&A."

Similar presentations


Ads by Google