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.

Slides:



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

Pemrograman C Risanuri Hidayat. Why C  Compact, fast, and powerful  “Mid-level” Language  Standard for program development (wide acceptance)  It is.
The Preprocessor Underlying C Language Features Copyright © 2012 by Yong-Gu Lee
The Assembly Language Level
Introduction to C Programming CE Lecture 1 Introduction to C.
 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.
1 Lecture 3  Lexical elements  Some operators:  /, %, =, +=, ++, --  precedence and associativity  #define  Readings: Chapter 2 Section 1 to 10.
QUOTATION This chapter teaches you about a unique feature of the shell programming language: the way it interprets quote characters. Basically, the shell.
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.
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.
CS 161 Introduction to Programming and Problem Solving Chapter 13 C++ Preprocessor Herbert G. Mayer, PSU Status 10/8/2014 Initial content copied verbatim.
21 August (B.V.Patel institute of BMC & IT) STRUCTURE AND UNIONS.
1 CSC103: Introduction to Computer and Programming Lecture No 26.
Computer Science 210 Computer Organization Introduction to C.
Windows Programming Lecture 05. Preprocessor Preprocessor Directives Preprocessor directives are instructions for compiler.
Chapter 3 Getting Started with C++
 2000 Prentice Hall, Inc. All rights reserved. Chapter 12 - The Preprocessor Directives (Macros)
Goals of Course Introduction to the programming language C Learn how to program Learn ‘good’ programming practices.
Macros. There are three basic phases for C programming. preprocessing, compiling, and linking. C input file is first passed to a preprocessing program.
© 2006 Pearson Education 1 Obj: cont 1.3 and 1.4, to become familiar with identifiers and to understand how programming languages work HW: p.51 #1.8 –
The Structure of a C++ Program. Outline 1. Separate Compilation 2. The # Preprocessor 3. Declarations and Definitions 4. Organizing Decls & Defs into.
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.
Introduction to Programming Using C Modularity. 2 Contents Modularity Functions Preprocessor Comments Global variables.
Sharda University P. K. Mishra (Asst.Prof) Department of Computer Science & Technology Subject Name: Programming Using C Sub Code: CSE-106 Programming.
Chapter 13 C Preprocessor C How to Program, 8/e ©2016 by Pearson Education, Inc., Hoboken, NJ. All Rights Reserved.
C Hints and Tips The preprocessor and other fun toys.
Engineering Computing I Chapter 4 Functions and Program Structure.
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.
 2003 Prentice Hall, Inc. All rights reserved. 1 IS 0020 Program Design and Software Tools Preprocessor Midterm Review Lecture 7 Feb 17, 2004.
Compiler Directives. The C Preprocessor u The C preprocessor (cpp) changes your source code based on instructions, or preprocessor directives, embedded.
Lecture-3 Functions and Recursion. C Preprocessor Includes header files like stdio.h Expands macros defined Handles conditional compilations PreprocessorProcessor.
THE PREPROCESSOR
The Preprocessor Directives Introduction Preprocessing – Occurs before program compiled Inclusion of external files Definition of symbolic constants.
 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 PREPROCESSOR. Introduction  It is a program that processes our source program before it is passed to the compiler.  Preprocessor commands (often known.
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.
MAHENDRAN. Session Objectives Session Objectives  Discuss the Origin of C  Features of C  Characteristics of C  Current Uses of C  “C” Programming.
Functions Chapter 5. Function A set of instructions that are designed to perform specific task. A complete and independent program. It is executed by.
Lecture 3 Translation.
13 C Preprocessor.
Chapter Topics The Basics of a C++ Program Data Types
What Is? function predefined, programmer-defined
Language Translation Compilation vs. interpretation.
Basic Elements of C++.
Chapter 13 - The Preprocessor
14. THE PREPROCESSOR.
' C ' PROGRAMMING SRM-MCA.
Pre-processor Directives
Basic Elements of C++ Chapter 2.
2.1 Parts of a C++ Program.
C Preprocessor(CPP).
Preprocessor.
Symbolic Constants in C
C Preprocessor Seema Chandak.
C Programming Language
Chapter 11: The Preprocessor
What Is? function predefined, programmer-defined
Introduction to Programming - 1
Conditional Compilation
Week 2 - Friday CS222.
Presentation transcript:

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 read, modify, portable and more efficient. Pre-processor is a program that processes the code before it passes through the compiler. It operates under the control of pre-processor command lines and directives. Source Program CompilerC PreprocessorObject Program

Preprocesses directives DirectivesFunction #defineDefines a macro substitution #undefUndefined a macro #includeSpecifies the files to be included #ifdefTests for a macro definition #endifSpecifies the end of #if #ifndefTests whether a macro is not defined #ifTests a compile-time condition #elseSpecifies alternatives when #if test fails Preprocessor directives follow the special syntax rules and begin with the symbol #and do not require any semicolon at the end. A set of commonly used preprocessor directives

Preprocesses directives The preprocessor directives can be divided into three categories 1. Macro substitution division 2. File inclusion(Including) division 3. Compiler control division

The Preprocessor MACRO SUBSTITUTION This is a process of replacing an identifier of a C program by a constant or a symbolic constant. This can be accomplished by the directive #define. The #definition is a macro definition statement. Syntax: #define identifier CSCE Where, #define A hash define directive Identifier A valid C identifier, conventionally written in upper case CSCE May be constant, symbolic constant or expression.

The Preprocessor Example: 1.#define MARKS #define AVERAGE #define PI Example Program #include #define PI main() { float rad,area; printf(“enter the radius”); scanf(“%f”,&rad); area= PI*rad*rad; printf(“area of a circle=%f”,area); } In this program, the macro PI is defined as hence, whenever PI occurs in a C program, it is replaced by the value

The Preprocessor FILE INCLUSION This is a process of inserting external files containing functions or macro definitions into the C program. An external file containing function can be include in a C program using the #include directive. Syntax: # include filename Where, # include Preprocessor directive for file inclusion Identifier Name of the file containing the required function definition to be include in a C program.

The Preprocessor FILE INCLUSION There is no space between #symbol and include. But,there must be at least one blank space between #include and filename. Filename can be written within a pair of a angle brackets or double quotation marks. Example: 1.#include 2.#include 3.#include “Grade.c” When the filename is written within a pair of angle,the specified file is searched only in the standard directories.But, when the filename is written in a pair of double quotes,the specified file is first searched in the current directory and then in the standard directories.

The Preprocessor CONDITIONAL DIRECTIVES C processor provides a conditional compilation directive which is used to select alternate segments of code in a C program depending upon the condition. Suppose there are two different version of a program, and they are more alike than are different. It will be redudant if you maintain both versions. We can overcome this problem by simply including both version in a single program. then, it would be possible to select a particular version depending on the requirement.

The Preprocessor CONDITIONAL DIRECTIVES Example: Main() { ………………….. #ifdef VERSION1 { …….. ……..Code of VERSION 1 …… } #else { ………… ……….Code of VERSION 2 …… ………. } #indif ……… } If we want to execute VERSION1 of a program then the following statement must be included in this program. #define VERSION1