Understanding Preprocessor Directives in Windows Programming: #define, #include, #if, and , Slides of Windows Programming

An in-depth exploration of preprocessor directives in windows programming. Learn about the various types of preprocessor directives, including #define, #include, #if, and others. Understand how these directives work, their syntax, and their significance in the compilation process. Discover examples of their usage and gain insights into preprocessor operators and standard predefined macros.

Typology: Slides

2011/2012

Uploaded on 11/06/2012

parasad
parasad 🇮🇳

4.5

(56)

131 documents

1 / 36

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Windows Programming
Lecture 05
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24

Partial preview of the text

Download Understanding Preprocessor Directives in Windows Programming: #define, #include, #if, and and more Slides Windows Programming in PDF only on Docsity!

Windows Programming

Lecture 05

Preprocessor

Preprocessor Directives

Preprocessor directives are instructions for

compiler.

Examples of Preprocessor

Directives

#define #error #undef #include

#if #else #elif #endif

#ifdef #line #ifndef #pragma

#define ARRAY_SIZE 10
Before Preprocessing
char array[ARRAY_SIZE];
After Preprocessing
char array[10];

identifier is not replaced if it appears

  • in a comment
  • within a string, or
  • as part of a longer identifier

#define directive

#define WIDTH 10

#define HEIGHT WIDTH+

HEIGHT is replaced with^ WIDTH+25 is replaced with 10+

#define directive

identifier remains defined and can be tested
  • It can be checked using #if and #ifdef
directives.
  • #if defined is same as #ifdef.

#if, #elif, #else

#elif is same as #else #if

Preprocessor Operators

The defined is a preprocessor operator.

#if defined MAX

is equivalent to

#ifdef MAX

Preprocessor operator

Preprocessor Directive

#error directive

  • The directive #error causes the preprocessor to report a fatal error. The rest of the line that follows #error is used as the error message. The line must consist of complete tokens.
  • You would use #error inside of a conditional statment

that detects a combination of parameters which you know the program does not properly support.

#error directive

#if !defined(__cplusplus)
#error Must use C++ language
#endif

#undef Directive

Once an identifier has been undefined, that
identifier may be redefined by a subsequent
#define directive. The new definition need not
have any resemblance to the old definition.

#undef Directive

#define SPEED ………… some code here…………… … … … … … … … #undef SPEED ifndef(SPEED) #error Speed not defined #endif