1 CSC103: Introduction to Computer and Programming Lecture No 26.

Slides:



Advertisements
Similar presentations
Mr. D. J. Patel, AITS, Rajkot 1 Operating Systems, by Dhananjay Dhamdhere1 Static and Dynamic Memory Allocation Memory allocation is an aspect of a more.
Advertisements

Systems Software.
Introduction to C Programming
Introduction to C Programming
CSc 352 An Introduction to the C Preprocessor Saumya Debray Dept. of Computer Science The University of Arizona, Tucson
CIS 101: Computer Programming and Problem Solving Lecture 9 Usman Roshan Department of Computer Science NJIT.
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 17 - The Preprocessor Outline 17.1Introduction 17.2The #include Preprocessor Directive 17.3The.
1 ICS103 Programming in C Lecture 2: Introduction to C (1)
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 13 - The Preprocessor Outline 13.1Introduction.
1 CSC 1401 S1 Computer Programming I Hamid Harroud School of Science and Engineering, Akhawayn University
1. 2 FUNCTION INLINE FUNCTION DIFFERENCE BETWEEN FUNCTION AND INLINE FUNCTION CONCLUSION 3.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 13 - The Preprocessor Outline 13.1Introduction 13.2The #include Preprocessor Directive 13.3The.
Introduction to C Programming
Macro & Function. Function consumes more time When a function is called, the copy of the arguments are passed to the parameters in the function. After.
21 August (B.V.Patel institute of BMC & IT) STRUCTURE AND UNIONS.
Windows Programming Lecture 05. Preprocessor Preprocessor Directives Preprocessor directives are instructions for compiler.
chap13 Chapter 13 Programming in the Large.
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.
Introduction to C Programming CE Lecture 7 Compiler options and makefiles.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
CHAPTER 2 PART #1 C++ PROGRAM STRUCTURE 1 st semester H 1 King Saud University College of Applied studies and Community Service Csc 1101 By:
C++ History C++ was designed at AT&T Bell Labs by Bjarne Stroustrup in the early 80's Based on the ‘C’ programming language C++ language standardised in.
C Hints and Tips The preprocessor and other fun toys.
SQL in a Programming Environment CIS 4301 Lecture Notes Lecture /11/2006.
ICS312 Set 14 MACROS. Macros The program structure is similar to that for procedures. As for procedure names, macro names represent a group of instructions.
CSC 107 – Programming For Science. Today’s Goal  Discuss writing functions that return values  return statement’s meaning and how it works  When and.
Introduction to C Programming Lecture 6. Functions – Call by value – Call by reference Arrays Today's Lecture Includes.
DOCUMENTATION SECTION GLOBAL DECLARATION SECTION
CSC141 Introduction to Computer Programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture - 6.
 2003 Prentice Hall, Inc. All rights reserved. 1 IS 0020 Program Design and Software Tools Preprocessor Midterm Review Lecture 7 Feb 17, 2004.
1 CSC103: Introduction to Computer and Programming Lecture No 24.
Compiler Directives. The C Preprocessor u The C preprocessor (cpp) changes your source code based on instructions, or preprocessor directives, embedded.
C++ Programming Lecture 13 Functions – Part V The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
C LANGUAGE Characteristics of C · Small size
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
JavaScript 101 Introduction to Programming. Topics What is programming? The common elements found in most programming languages Introduction to JavaScript.
Lecture-3 Functions and Recursion. C Preprocessor Includes header files like stdio.h Expands macros defined Handles conditional compilations PreprocessorProcessor.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 13 - The Preprocessor Outline 13.1Introduction 13.2The #include Preprocessor Directive 13.3The.
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 CSC103: Introduction to Computer and Programming Lecture No 27.
1 CSC103: Introduction to Computer and Programming Lecture No 16.
C language + The Preprocessor. + Introduction The preprocessor is a program that processes that source code before it passes through the compiler. It.
Preocedures A closer look at procedures. Outline Procedures Procedure call mechanism Passing parameters Local variable storage C-Style procedures Recursion.
1 CSC103: Introduction to Computer and Programming Lecture No 17.
CSE 303 Concepts and Tools for Software Development Richard C. Davis UW CSE – 10/11/2006 Lecture 7 – Introduction to C.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 330 Programming Language Structures Operational Semantics (Slides mainly.
LECTURE 3 Translation. PROCESS MEMORY There are four general areas of memory in a process. The text area contains the instructions for the application.
Pre-Compiler Directives for TTCN-3 Ina Schieferdecker in response to CR5089 and 5090.
C++ Programming Lecture 13 Functions – Part V By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
Lecture 3 Translation.
Chapter 2 - Introduction to C Programming
CISC105 – General Computer Science
Chapter 2 part #1 C++ Program Structure
Chapter 13 - The Preprocessor
CSC113: Computer Programming (Theory = 03, Lab = 01)
KALINGA INSTITUTE OF INDUSTRIAL TECHNOLOGY
Chapter 2 - Introduction to C Programming
Pre-processor Directives
Preprocessor C program → Modified C program → Object Code
Basic C++ What’s a declaration? What’s a definition?
C Preprocessor(CPP).
Preprocessor.
CSc 352 An Introduction to the C Preprocessor
Chapter 11: The Preprocessor
Introduction to Programming - 1
Conditional Compilation
Presentation transcript:

1 CSC103: Introduction to Computer and Programming Lecture No 26

2 Previous lecture Pointer to a structure Dynamic memory allocation for structure Passing a structure to a function

3 Today’s lecture outline Example program – structure C preprocessor directives Macro expansion File inclusion Conditional Compilation

4 Example Program Create a structure to specify data on students given below: Roll number, Name, Department, Course, Year of joining Create a variable of that structure, input value from user and then display those values. Write a program

5 Preprocessor directive Preprocessor directives are the special instruction to C compiler Preprocessor directive are resolved before compilation of program Each preprocessor directive begins with # and can be placed anywhere in the program Following preprocessor directives are used mostly Macro expansion File inclusion Conditional Compilation

6 Macro expansion Preprocessor Macro definition

7 Cont. && ||

8 Cont. A #define directive could be used to replace a condition

9 Cont. A #define directive could be used to replace an entire C statement.

10 Macros with Arguments Preprocessor

11 Multi line marcos Go to program

12 Macros versus Functions It seams that macro calls are ‘like’ function calls, they are not really the same things In a macro call the preprocessor replaces the macro template with its macro expansion In function call control is transferred to a function, function do processing and then control is returned back Macro call and expansion

13 Cont. when is it best to use macros with arguments and when is it better to use a function Usually macros make the program run faster but increase the program size whereas functions make the program smaller and compact E.g. if we used macro 100 times, then macro expansion goes in source code 100 time before compilation process If a function is called 100 times, it will make same amount of space in the program

14 Cont.. Conclusion: – If macro is simple and small than it can be used to avoid function calls overhead – But if macro size is larger than it is better to used function

15 File Inclusion This directive causes one file to be included in another #include Why we need it – It is a good programming practice to keep different sections of a large program separate in form of files. These files are #included at the beginning of main program file. – There are some functions and some macro definitions that we need almost in all programs that we write #include

16 include Ways to write #include statement #include "filename" #include "filename" – This would look for the file filename in the current folder and than in the include folder. C:\Dev-Cpp\include #include #include – This command would look for the file filename in the include folder only. Go to program

17 Conditional Compilation This allows to skip some part of the source code for compilation process General form #ifdef macroname statement 1 ; statement 2 ; statement 3 ; #endif

18 Where would #ifdef be useful To “comment out” some lines of code Go to program

19 Cont. A sophisticated use of #ifdef has to do with making the programs portable, i.e. to make them work on two totally different computers

20