12 주 강의 The preprocessor. The use of #include #include #include “ filename ” ::: current directory  system-dependent places #include ::: system dependent.

Slides:



Advertisements
Similar presentations
Character Arrays (Single-Dimensional Arrays) A char data type is needed to hold a single character. To store a string we have to use a single-dimensional.
Advertisements

Files in C Rohit Khokher.
C Characters & Strings Character Review Character Handling Library Initialization String Conversion Functions String Handling Library Standard Input/Output.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Characters and Strings.
Programming Character I/O. COMP102 Prog. Fundamentals I: Character I/O/ Slide 2 More on char Type l Constant Declaration: const char star = '*'; l Variable.
Programming C/C++ on Eclipe Trình bày : Ths HungNM C/C++ Training.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 8 - Characters and Strings Outline 8.1Introduction 8.2Fundamentals of Strings and Characters 8.3Character.
Lecture 2: Character Input/Output in C
Chapter 8 Characters and Strings Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 8 - Characters and Strings Outline 8.1Introduction.
Character I/O. COMP104 Character I/O Slide 2 Data Type: char * Constant declaration const char star = '*'; * Variable declaration char resp; * Variable.
The Preprocessor Chapter 8 in ABC. #define PI #define C /* speed of light */ #define EOF (-1) #define MAXINT #define ITERS.
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 17 - The Preprocessor Outline 17.1Introduction 17.2The #include Preprocessor Directive 17.3The.
1 Character Processing How characters can be treated as small integers? How characters are stored and manipulated in a machine? How use is made of certain.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 13 - The Preprocessor Outline 13.1Introduction.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 13 - The Preprocessor Outline 13.1Introduction 13.2The #include Preprocessor Directive 13.3The.
 2007 Pearson Education, Inc. All rights reserved C Characters and Strings.
The Preprocessor #include #define N 10 C program Preprocessor Modified C program Preprocessor Object codes.
C How to Program, 6/e © by Pearson Education, Inc. All Rights Reserved.
 2007 Pearson Education, Inc. All rights reserved C Preprocessor.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 19 - The Preprocessor Outline 19.1 Introduction 19.2 The #include Preprocessor Directive 19.3.
CMPE-013/L: “C” Programming Gabriel Hugh Elkaim – Spring 2013 CMPE-013/L Pre-Processor Commands Gabriel Hugh Elkaim Spring 2013.
First Program in C With Output. C Language Keywords.
Windows Programming Lecture 05. Preprocessor Preprocessor Directives Preprocessor directives are instructions for compiler.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 12 - The Preprocessor Directives (Macros)
 2007 Pearson Education, Inc. All rights reserved C Characters and Strings.
EPSII 59:006 Spring Introduction Fundamentals of Strings and Characters Character Handling Library String Conversion Functions Standard Input/Output.
Macros. There are three basic phases for C programming. preprocessing, compiling, and linking. C input file is first passed to a preprocessing program.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 8 - Characters and Strings Outline 8.1Introduction 8.2Fundamentals of Strings and Characters 8.3Character.
February 14, 2005 Characters, Strings and the String Class.
Chapter 13 C Preprocessor C How to Program, 8/e ©2016 by Pearson Education, Inc., Hoboken, NJ. All Rights Reserved.
Fundamentals of C and C++ Programming. EEL 3801 – Lotzi Bölöni Sub-Topics  Basic Program Structure  Variables - Types and Declarations  Basic Program.
1 Preprocessor –How it works File Inclusion: #include Macro Definition: #define Predefined macros –__LINE__, __FILE__, __DATE__, __TIME__ Conditional Compilation.
C How to Program, 7/e © by Pearson Education, Inc. All Rights Reserved.
 2003 Prentice Hall, Inc. All rights reserved. 1 IS 0020 Program Design and Software Tools Preprocessing Lecture 12 April 7, 2005.
Arrays II (Strings). Data types in C Integer : int i; Double: double x; Float: float y; Character: char ch; char cha[10], chb[]={‘h’,’e’,’l’,’l’,’o’};
Created by Harry H. Cheng,  2009 McGraw-Hill, Inc. All rights reserved. C for Engineers and Scientists: An Interpretive Approach Chapter 7: Preprocessing.
1 Object-Oriented Programming -- Using C++ Andres, Wen-Yuan Liao Department of Computer Science and Engineering De Lin Institute of Technology
 2003 Prentice Hall, Inc. All rights reserved. 1 IS 0020 Program Design and Software Tools Preprocessor Midterm Review Lecture 7 Feb 17, 2004.
More Pointers and Arrays Kernighan/Ritchie: Kelley/Pohl: Chapter 5 Chapter 6.
THE PREPROCESSOR
The Preprocessor Directives Introduction Preprocessing – Occurs before program compiled Inclusion of external files Definition of symbolic constants.
CTYPE.H Introduction  The ctype header is used for testing and converting characters.  A control character refers to a character that.
Lecture 18 CIS 208 Wednesday, March 30, Test2 April 15 th : Happy Tax day. Review: Wednesday, the 13 th.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 13 - The Preprocessor Outline 13.1Introduction 13.2The #include Preprocessor Directive 13.3The.
Sudeshna Sarkar, IIT Kharagpur 1 I/O in C + Misc Lecture –
1 Character Input/Output in C COS 217
13 C Preprocessor.
C Characters and Strings
Predefined Macros (examples)
C Characters and Strings
Character Processing How characters can be treated as small integers?
INC 161 , CPE 100 Computer Programming
Chapter 13 - The Preprocessor
Functions Separate Compilation
14. THE PREPROCESSOR.
I/O in C + Misc Lecture Sudeshna Sarkar, IIT Kharagpur.
Chapter 8 - Characters and Strings
Enumerations.
Introduction to Programming
Introduction to Programming
Decision Making.
Enumerations.
C Preprocessor(CPP).
Character Processing How characters can be treated as small integers?
C Preprocessor Seema Chandak.
Chapter 11: The Preprocessor
The Preprocessor.
Characters and Strings Functions
C Characters and Strings
Presentation transcript:

12 주 강의 The preprocessor

The use of #include #include #include “ filename ” ::: current directory  system-dependent places #include ::: system dependent places  unix :: /usr/include

#define #define identifier token_string #define PI #define SECONDS_PER_DAYS (60*60*24) Syntactic sugar –#define EQ == –#define do /* blank */ –while (I EQ 1) do { ….

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

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

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

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)

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 *)

Macros with arguments 377 page 설명

The Macros in stdio.h and ctype.h – #define getchar() getc(stdin) – #define putchar(c) put((c), stdout)

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

(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

Conditional compilation #if constant_integral_expression #ifdef identifier #ifndef identifier #endif #undef identifier defined identifier – defined(identifier )

예 #if defined(HP9000) || defined(SUN4) && !defined(VAX) …. /*machine-dependent code */ #endif #define DEBUG 1 #if DEBUG printf( “ debug: a = %d\n ”, a); #endif

예2예2 #define DEBUG #ifdef DEBUG ….. #endif #include “ everything.h ” #undef PIE #define PIE “ I like apple. ”

#elif, #else #elif #endif #if #elif #else #endif

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

# (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; }

## (ANSI C) Merge tokens #define X(i) x##i X(1) = X(2) = X(3);  x1 = x2 = x3

assert() assert(p != NULL); assert(n>0 && n<7); 389 page 설명

#error, #pragma #if A_SIZE < B_SIZE #error “ Incompatible sizes ” #endif #pragma tokens

Line Numbers, etc. #line integral_constant “ filename ” #undefine isalpha /* access the function, not the macro */

Quicksort 간단히 설명 모르면 넘어간다

숙제 학교 1, 6, 8 집 5, 7, 13, 16, 20, 을 해결하면 추가 점수 부여