CS 202 Computer Science II Lab Fall 2009 October 1.

Slides:



Advertisements
Similar presentations
CS 11 C track: lecture 7 Last week: structs, typedef, linked lists This week: hash tables more on the C preprocessor extern const.
Advertisements

Compilation and Debugging 101. Compilation in C/C++ hello.c Preprocessor Compiler stdio.h tmpXQ.i (C code) hello.o (object file)
Programming III SPRING 2015 School of Computer and Information Sciences Francisco R. Ortega, Ph.D. McKnight Fellow and GAANN Fellow LECTURE #3 Control.
1 10/20/08CS150 Introduction to Computer Science 1 do/while and Nested Loops Section 5.5 & 5.11.
 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.
Programming C/C++ on Eclipe Trình bày: Ths HungNM C/C++ Training.
 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 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.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 12 - The Preprocessor Directives (Macros)
CONTROL FLOW IN C++ Satish Mishra PGT CS KV Trimulgherry.
Macros. There are three basic phases for C programming. preprocessing, compiling, and linking. C input file is first passed to a preprocessing program.
C++ Basics Structure of a Program. C++ Source Code Plain text file Typical file extension .CPP Must compile the C++ source code without errors before.
The Structure of a C++ Program. Outline 1. Separate Compilation 2. The # Preprocessor 3. Declarations and Definitions 4. Organizing Decls & Defs into.
Introduction to C Programming CE Lecture 7 Compiler options and makefiles.
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.
/* Documentations */ Pre process / Linking statements Global declarations; main( ) { Local Declarations; Program statements / Executable statements; }
C Hints and Tips The preprocessor and other fun toys.
COMPUTER PROGRAMMING. Iteration structures (loops) There may be a situation when you need to execute a block of code several number of times. In general,
CPS120: Introduction to Computer Science Lecture 14 Functions.
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.
Control Structures (B) Topics to cover here: Sequencing in C++ language.
Dr. Mark L. HornickCS-1030 Dr. Mark Hornick 1 C++ Global functions Declarations & Definitions Preprocessor Directives.
1 8/31/05CS150 Introduction to Computer Science 1 Hello World!
 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.
1 Lecture08: Program Development & Preprocessor 11/12/2012 Slides modified from Yin Lou, Cornell CS2022: Introduction to C.
Program in Multiple Files. l all C++ statements are divided into executable and non-executable l executable - some corresponding machine code is generated.
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.
Refer to Ivor Horton’s Beginning ANSI C++ The Complete Language, 3rd Ed. APress Media, LLC. Program Files and Preprocessing Directives Program files and.
Lecturer: Nguyen Thi Hien Software Engineering Department Home page: hienngong.wordpress.com Chapter 2: Language C++
Dr. Mark L. HornickCS-1030 Dr. Mark Hornick 1 C++ Global functions Declarations & Definitions Preprocessor Directives.
Lecture 01d: C++ review Topics: functions scope / lifetime preprocessor directives header files C structures ("simple classes")
Software Engineering Algorithms, Compilers, & Lifecycle.
Unit 10 Code Reuse. Key Concepts Abstraction Header files Implementation files Storage classes Exit function Conditional compilation Command-line arguments.
COM S 326X Deep C Programming for the 21st Century Prof. Rozier
13 C Preprocessor.
What Is? function predefined, programmer-defined
INC 161 , CPE 100 Computer Programming
Chapter 13 - The Preprocessor
14. THE PREPROCESSOR.
Programmer-Defined Functions, Call-by-Value, Multiple Files Lab 5
Pre-processor Directives
Introduction to Programming
Learning Objectives What else in C++ Bitwise operator
Preprocessor C program → Modified C program → Object Code
Structures putting data together.
Separate Compilation.
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).
Comments, Prototypes, Headers & Multiple Source Files
Chapter 3: Input/Output
Namespaces How Shall I Name Thee?.
Control Structures Part 3
Homework Finish up K&R Chapters 3 & 4
C Preprocessor Seema Chandak.
C Programming Language
Chapter 11: The Preprocessor
What Is? function predefined, programmer-defined
Conditional Compilation
Preprocessor Directives and Macros Chapter 21
Presentation transcript:

CS 202 Computer Science II Lab Fall 2009 October 1

Today Topics Pre-Processor Directive

Pre-Processor Pre-Processor Directive : An instruction to the compiler to do something before compiling the source code, declared by using “#” symbol Pre-Processor : A program that handles these directive. It’s because the program has to do some processing before the compilation process starts. Pre-Processor Directive Location : – Usually at the beginning of the source file. – Also possible inside the source code.

Important Directive #include #define & #undef #if #endif #else #elif #ifdef #ifndef

#include Header File : An external file whose contents are included into program by using the “#include” Include unused library : Increase compilation time. #include – #include #include “user_file” – #include “my_header.h” – #include “my_file.cpp” Difference : With “ ” the compiler will look at the default header file directory, where as the other will look at the path specified under quotation mask

#define & #undef Substitutions In program #define identifier sequence_of_characters – #define array_size 100 #define identifier(list_of_identifiers) substitution_string – #define max(x, y) x>y ? x:y #undefine identifier : usually use with logical preprocessor directive – #undefine block1

Logical Preprocessor Directive Conditional Compilation – #if defined identifier – #endif Directive Testing for Specific Values – #if constant_expression Multiple Choice Selections – #if – #else or #elif – #endif

Conditional Compilation #if defined identifier or #ifdef // if specifics identifier is defined the code after // #if statement will be executed until #endif #endif #if !defined identifier or #ifndef #define identifier // block of code that you don’t want to repeat it // to avoid duplication of code #endif

test1 //test 1 //#define myEndl endl cout<<“no syntax error!!!!!"<<myEndl; //end test 1

test2 //test 2 int a; #define myCin cin>> #define myCout cout<< myCin a; myCout a; //end test 2

test3 #define testDef 25 cout<<"testDef: "<<testDef<<endl; #ifdef testDef #if testDef == 24 cout<<"not equal"<<endl; #elif testDef == 25 cout<<"equal"<<endl; #endif #undef testDef #ifndef testDef cout<<"not defined"<<endl; #else cout<<"defined"<<endl; #endif

test4 //test 4 #define myMax(a,b) (a>b?a:b) int x = 12, y = 23; cout<<myMax(x,y)<<endl; #undef myMax // cout<<myMax(x,y)<<endl; //end test 4

Directives Testing for Specific Values To test the value of a constant expression. If the value of the constant expression is not zero, the block of code will be executed until #endif #if CPU == Pentium cout << “Performance should be good.” << endl; #endif The above example will be included into your program only if you previously defined CPU with the value of Pentium

Multiple Choice Selections #if CPU == Pentium cout << “Performance should be good.” << endl; #else cout << “Performance might not be good.” << endl; #endif #if CPU == XEON_PIV cout << “Performance is very good.” << endl; #elif CPU == Pentium cout << “Performance should be good.” << endl; #else cout << “Performance might not be good.” << endl; #endif

Questions?