Introduction to Programming

Slides:



Advertisements
Similar presentations
Compilation and Debugging 101. Compilation in C/C++ hello.c Preprocessor Compiler stdio.h tmpXQ.i (C code) hello.o (object file)
Advertisements

Functions, Projects, and C++ I/O Streams Dr. Nancy Warter-Perez June 4, 2003.
The C Preprocessor Yongjoon Lee April 22, What is it? Things with # –#include Processes the C source files BEFORE handing it to compiler. –`Pre`-process.
 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.
CS 202 Computer Science II Lab Fall 2009 October 1.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 13 - The Preprocessor Outline 13.1Introduction 13.2The #include Preprocessor Directive 13.3The.
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.
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)
Macros. There are three basic phases for C programming. preprocessing, compiling, and linking. C input file is first passed to a preprocessing program.
Introduction to C Programming CE Lecture 7 Compiler options and makefiles.
Fundamentals of C and C++ Programming. EEL 3801 – Lotzi Bölöni Sub-Topics  Basic Program Structure  Variables - Types and Declarations  Basic Program.
CS 213 Fall 1998 Namespaces Inline functions Preprocessing Compiling Name mangling Linking.
CSCI 171 Presentation 8 Built-in Functions, Preprocessor Directives, and Macros.
L function n predefined, programmer-defined l arguments, (formal) parameters l return value l function call, function invocation l function definition.
 2003 Prentice Hall, Inc. All rights reserved. 1 IS 0020 Program Design and Software Tools Preprocessing Lecture 12 April 7, 2005.
1 Original Source : and Problem and Problem Solving.ppt.
 2003 Prentice Hall, Inc. All rights reserved. 1 IS 0020 Program Design and Software Tools Preprocessor Midterm Review Lecture 7 Feb 17, 2004.
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
C PREPROCESSOR. Introduction  It is a program that processes our source program before it is passed to the compiler.  Preprocessor commands (often known.
1 TOPICS TO DISCUSS : FUNCTIONS TYPES OF FUNCTIONS HEADER FILES PRESENTED BY : AVISHEK MAJUMDAR(837837) GUNJAN AGARWAL(856587) SATYAPRIYA DEY(856624)
Lecture 01d: C++ review Topics: functions scope / lifetime preprocessor directives header files C structures ("simple classes")
Pre-Compiler Directives for TTCN-3 Ina Schieferdecker in response to CR5089 and 5090.
1 Building a program in C: Preprocessor, Compilation and Linkage.
1 CS 192 Lecture 4 Winter 2003 December 8-9, 2003 Dr. Shafay Shamail.
13 C Preprocessor.
Basic concepts of C++ Presented by Prof. Satyajit De
What Is? function predefined, programmer-defined
Computer Science 210 Computer Organization
Introduction to Programming
Standard Input - Output
CISC105 – General Computer Science
INC 161 , CPE 100 Computer Programming
Chapter 13 - The Preprocessor
BASIC ELEMENTS OF A COMPUTER PROGRAM
Functions Separate Compilation
14. THE PREPROCESSOR.
Programmer-Defined Functions, Call-by-Value, Multiple Files Lab 5
Pre-processor Directives
Computer Science 210 Computer Organization
Preprocessor C program → Modified C program → Object Code
Chapter 2 Elementary Programming
Structures putting data together.
Introduction to Programming
مباني كامپيوتر و برنامه سازي
C Preprocessor(CPP).
Preprocessor.
الوحدة الرابعة البرمجة وصياغة حل المسائل البرمجة وأهميتها أهداف الدرس الأول مفهوم البرمجة. الفرق بين المبرمج ومستخدم البرنامج. الحاجة إلى البرامج.
Programming in C Miscellaneous Topics.
Accomplishing Executables
Programming in C Miscellaneous Topics.
C Preprocessing File I/O
C Preprocessor Seema Chandak.
C Programming Language
Introduction to Programming
Chapter 11: The Preprocessor
What Is? function predefined, programmer-defined
Introduction to Programming
The Preprocessor.
Programming Fundamental
Week 2 - Friday CS222.
Preprocessor Directives and Macros Chapter 21
Presentation transcript:

Introduction to Programming Lecture 23 Preprocessors and Header files

Today’s Lecture Preprocessor Directives Header Files Macros

Preprocessor

#include <iostream.h>

#

#include #include <iostream.h> #include <stdlib.h> #include <fstream.h> #include <stream.h>

5:10 to 5:23

5:24 to 5:41

Re-locatable Executable

MyHeader.h

#include “MyHeader.h”

#include <iostream.h>

#define

#define PI 3.141592

Preprocessor Directives #if #else #endif #elif #ifdef #ifndef #error

Preprocessor Directives #ident #import #line #machine #system #warning

Example #ifdef PI

# define PI # ifdef PI

# define DEBUG # ifdef DEBUG

Conditional Compilation Macro Translation

#undef DEBUG

#include <conio.h>       #include <conio.h> Consol Input Output  

#include <conio.h> #include <conio.c>

int getche ( ) ;

Get Character With Echo

#ifdef __cplusplus extern "C" { #endif - - }

Macro

Example 1 #define SQUARE ( X ) X * X main ( ) { int i = 5 , j ; : } i * i ; SQUARE ( i ) ;

Example 2 #define SQUARE ( X ) X * X main ( ) { int i = 5 , j = 10 , k ; : k = } i + j * i + j ; SQUARE ( i + j ) ;

Example 3 #define SQUARE(X) (X)*(X) main ( ) { int i = 5 , j = 10 , k ; k = } SQUARE ( i + j ) ; ( i + j ) * ( i + j ) ;

Overhead

Code Bloat

Example 4 #define PI 3.14159 #define CIRCLEAREA ( X ) main ( ) { float radius ; cout << “ Enter radius of Circle Area : ” ; cin >> radius ; cout << “ Area of Circle Area is ” << } ( ( PI ) * ( X ) * ( X ) ) PI * X * X CIRCLEAREA ( 2 * radius ) ; CIRCLEAREA ( radius ) ; ( ( PI ) * ( radius ) * ( radius ) ) ;

Header Files

Header File #include <iostream.h> #include <stdlib.h> #include <stdio.h> #include <string.h>

In Next Lecture Memory Allocation