THE PREPROCESSOR. Preprocessing is (apparently) done before actual compilation begins. The preprocessor doesnt know (very much) C. Major kinds of preprocessor.

Slides:



Advertisements
Similar presentations
SYMBOL TABLES &CODE GENERATION FOR EXECUTABLES. SYMBOL TABLES Compilers that produce an executable (or the representation of an executable in object module.
Advertisements

CSc 352 An Introduction to the C Preprocessor Saumya Debray Dept. of Computer Science The University of Arizona, Tucson
A simple C++ program /* * This program prints the phrase "Hello world!" * on the screen */ #include using namespace std; int main () { cout
ספטמבר 04Copyright Meir Kalech1 C programming Language Chapter 10: Appendices.
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 17 - The Preprocessor Outline 17.1Introduction 17.2The #include Preprocessor Directive 17.3The.
© 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.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Basic Elements of C++ Chapter 2.
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.
The Pre-processor A unique feature of c language is the pre-processor. A program can use the tools provided by pre-processor to make his program easy to.
Windows Programming Lecture 05. Preprocessor Preprocessor Directives Preprocessor directives are instructions for compiler.
2.2 A Simple Syntax-Directed Translator Syntax-Directed Translation 2.4 Parsing 2.5 A Translator for Simple Expressions 2.6 Lexical Analysis.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 12 - The Preprocessor Directives (Macros)
C Programming Functions Macros. Functions vs. Methods Java classes include methods which can be called from any code with appropriate access (recall public.
Macros. There are three basic phases for C programming. preprocessing, compiling, and linking. C input file is first passed to a preprocessing program.
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
1 Homework / Exam Finish up K&R Chapters 3 & 4 Starting K&R Chapter 5 Next Class HW4 due next class Go over HW3 solutions.
C++ Character Set It is set of Characters/digits/symbol which is valid in C++. Example – A-Z, (white space) C++ Character Set It is set of.
Chapter 13 C Preprocessor C How to Program, 8/e ©2016 by Pearson Education, Inc., Hoboken, NJ. All Rights Reserved.
Property of Jack Wilson, Cerritos College1 CIS Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College.
Computer Engineering Rabie A. Ramadan Lecture 5.
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.
Introduction to Programming
 2003 Prentice Hall, Inc. All rights reserved. 1 IS 0020 Program Design and Software Tools Preprocessing Lecture 12 April 7, 2005.
Templates L. Grewe. 2 Goals Often want to do basically the same thing w/diff things –functions work on variables only types specified –  algorithmic.
IN LINE FUNCTION AND MACRO Macro is processed at precompilation time. An Inline function is processed at compilation time. Example : let us consider this.
1 Remember: Examination is a chance not ability. By ILTAF MEHDI, IT LECTURER, MIHE, KATR-E-PARWAN BRANCH, KABUL.
 2003 Prentice Hall, Inc. All rights reserved. 1 IS 0020 Program Design and Software Tools Preprocessor Midterm Review Lecture 7 Feb 17, 2004.
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 8 – C: Miscellanea Control, Declarations, Preprocessor, printf/scanf.
Minimal standard C program int main(void) { return 0 ; }
Operating System Discussion Section. The Basics of C Reference: Lecture note 2 and 3 notes.html.
THE PREPROCESSOR
The Preprocessor Directives Introduction Preprocessing – Occurs before program compiled Inclusion of external files Definition of symbolic constants.
Chapter 14: The Preprocessor Copyright © 2008 W. W. Norton & Company. All rights reserved. 1 Chapter 14 The Preprocessor.
Templates Where the TYPE is generic. Templates for functions Used when the you want to perform the same operation on different data types. The definition.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 13 - The Preprocessor Outline 13.1Introduction 13.2The #include Preprocessor Directive 13.3The.
© Oxford University Press All rights reserved. CHAPTER 10 THE PREPROCESSOR DIRECTIVE.
1 Object-Oriented Programming -- Using C++ Andres, Wen-Yuan Liao Department of Computer Science and Engineering De Lin Institute of Technology
Adv. UNIX:pre/111 Advanced UNIX v Objectives of these slides: –look at the features of the C preprocessor Special Topics in Comp. Eng.
C language + The Preprocessor. + Introduction The preprocessor is a program that processes that source code before it passes through the compiler. It.
2. C FUNDAMENTALS. Example: Printing a Message /* Illustrates comments, strings, and the printf function */ #include int main(void) { printf("To C, or.
Pre-Compiler Directives for TTCN-3 Ina Schieferdecker in response to CR5089 and 5090.
COM S 326X Deep C Programming for the 21st Century Prof. Rozier
13 C Preprocessor.
Chapter Topics The Basics of a C++ Program Data Types
CSC201: Computer Programming
A Simple Syntax-Directed Translator
Compiler Construction (CS-636)
INC 161 , CPE 100 Computer Programming
Basic Elements of C++.
Chapter 13 - The Preprocessor
Functions Separate Compilation
14. THE PREPROCESSOR.
KALINGA INSTITUTE OF INDUSTRIAL TECHNOLOGY
Pre-processor Directives
Basic Elements of C++ Chapter 2.
Register Variables Declaring a variable as a "register" variable is an advisory to the compiler to keep the normal location of the variable in a register,
C Preprocessor(CPP).
Exam 4 review Copyright © 2008 W. W. Norton & Company.
CSc 352 An Introduction to the C Preprocessor
Chapter # 2 Part 2 Programs And data
C Preprocessor Seema Chandak.
The C Language: Intro.
Macro A fragment of code which has been given a name.
Preprocessor Directives and Macros Chapter 21
Presentation transcript:

THE PREPROCESSOR

Preprocessing is (apparently) done before actual compilation begins. The preprocessor doesnt know (very much) C. Major kinds of preprocessor directives: Macro definition Conditional compilation File inclusion

THE PREPROCESSOR Rules for using preprocessor directives: Must begin with a #. May contain extra spaces and tabs.

Simple Macros Form of a simple macro: #define identifier replacement-list The replacement list can be any sequence of C tokens, including identifiers, keywords, numbers, character constants, string literals, operators, and punctuation.

Simple Macros Examples of simple macros: #define N 100 #define PI #define CR '\r' #define WARNING "Warning: nonstandard feature" #define BEGIN { #define END } #define BOOL int #define N 100; int a[N]; /* becomes int a[100;]; */

Parameterized Macros Form of a parameterized macro: #define identifier(x1, x2, …, xn) replacement-list There must be no space between the identifier and the left parenthesis. Parameterized macros often serve as simple functions. Examples of parameterized macros: #define MAX(x,y) ((x)>(y)?(x):(y)) #define EVEN(n) ((n) % 2 == 0) #define ODD(n) ((n) % 2 != 0)

Parameterized Macros Advantages of using a parameterized macro instead of a function: The compiled code will execute more rapidly. Macros are generic. Disadvantages of using a parameterized macro instead of a function: The compiled code will often be larger. Arguments arent type-checked. Its not possible to have a pointer to a macro. A macro may evaluate its arguments more than once

General Properties of Macros One macro may be defined in terms of another: #define PI #define TWO_PI (2*PI) When the preprocessor encounters the symbol TWO_PI later in the program, it replaces it by (2*PI). The preprocessor then rescans the replacement list to see if it contains invocations of other macros (PI in this case). The preprocessor will rescan the replacement list as many times as necessary to eliminate all macro names.