Download presentation
Presentation is loading. Please wait.
Published bySophia Gabriella Lane Modified over 9 years ago
1
12 주 강의 The preprocessor
2
The use of #include #include #include “ filename ” ::: current directory system-dependent places #include ::: system dependent places unix :: /usr/include
3
#define #define identifier token_string #define PI 3.14159 #define SECONDS_PER_DAYS (60*60*24) Syntactic sugar –#define EQ == –#define do /* blank */ –while (I EQ 1) do { ….
4
Macros with arguments #define identifier(identifier, …, identifier) token_string opt #define SQ(x) ((x)*(x)) –SQ(7+w) ((7+w)*(7+w)) –SQ(SQ(*p)) ((((*p) * (*p))) * (((*p) * (*p)))) #define SQ(x) x*x –SQ(a+b) a + b * a + b
5
Micros(Cont.) #define SQ(x) (x) * (x) –4/SQ(2) 4/(2)*(2) #define SQ (x) ((x) * (x)) –SQ(7) (x) ((x) * (x)) (7) #define SQ(x) ((x) * (x); /* error */ – x=SQ(y); x = ((y)*(y));; – if (x ==2) x=SQ(y); else ++x; syntax error
6
Micros(cont.) #define min(x,y) (((x) < (y)) ? (x) : (y)) m=min(u,v) ; #define SQ(x) ((x) * (x)) #define CUBE(x) (SQ(x) * (x)) #define F_POW(x) sqrt(sqrt(CUBE(x))) #undef identifier –Undef F_POW
7
Type definitions and stddef.h typedef char uppercase; stddef.h – typedef int ptrdiff_t; – typedef short wchar_t; – typedef unsigned size_t; #define NULL ((void *) 0)
8
Sorting with qsort() stdlib.h – void qsort(void *array, size_t n_els, size_t el_size, int compare(const void *, const void *)); – int compare(const void *, const void *)
9
Macros with arguments 377 page 설명
10
The Macros in stdio.h and ctype.h – #define getchar() getc(stdin) – #define putchar(c) put((c), stdout)
11
MacroNonzero (true) is returned if: isalpha(c )c is a letter isupper(c )c is an uppercase letter islower (c )c is a lowercase letter isdigit (c )c is a digit isalnum (c )c is a letter or digit isxdigit (c )c is a hexadecimal digit isspace (c )c is a white space character ispunct (c )c is a punctuation character isprint (c )c is printable character isgraph (c )c is printable, but not a space iscntrl (c )c is a control character isascii(c )c is an ASCII code
12
(cont.) Call to the function or macro Value returned toupper(c )corresponding uppercase value or c tolower(c )corresponding lowercase value or c toascii(c )corresponding ASCII value
13
Conditional compilation #if constant_integral_expression #ifdef identifier #ifndef identifier #endif #undef identifier defined identifier – defined(identifier )
14
예 #if defined(HP9000) || defined(SUN4) && !defined(VAX) …. /*machine-dependent code */ #endif #define DEBUG 1 #if DEBUG printf( “ debug: a = %d\n ”, a); #endif
15
예2예2 #define DEBUG #ifdef DEBUG ….. #endif #include “ everything.h ” #undef PIE #define PIE “ I like apple. ”
16
#elif, #else #elif #endif #if #elif #else #endif
17
Predefined macros PredefinedValue _DATE_A string containing the current date _FILE_A string containing the file name _LINE_An integer representing the current line number _STDC_ If the implementation follows ANSI Standard C, then the value the is a nonzero integer _TIME_A string containing the current time
18
# (ANSI C) # stringization –#define message_for(a,b) \ printf(#a “ and ” #b “ : We love you!\n ” ) int main(void) { message_for(Carole, Debra); return 0; }
19
## (ANSI C) Merge tokens #define X(i) x##i X(1) = X(2) = X(3); x1 = x2 = x3
20
assert() assert(p != NULL); assert(n>0 && n<7); 389 page 설명
21
#error, #pragma #if A_SIZE < B_SIZE #error “ Incompatible sizes ” #endif #pragma tokens
22
Line Numbers, etc. #line integral_constant “ filename ” #undefine isalpha /* access the function, not the macro */
23
Quicksort 간단히 설명 모르면 넘어간다
24
숙제 학교 1, 6, 8 집 5, 7, 13, 16, 20, 21 30 을 해결하면 추가 점수 부여
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.