CISC105 – General Computer Science

Slides:



Advertisements
Similar presentations
Lecture 3 Some commonly used C programming tricks. The system command Project No. 1: A warm-up project.
Advertisements

Introduction to C++ An object-oriented language Unit - 01.
Compilation and Debugging 101. Compilation in C/C++ hello.c Preprocessor Compiler stdio.h tmpXQ.i (C code) hello.o (object file)
Structure of a C program
ספטמבר 04Copyright Meir Kalech1 C programming Language Chapter 10: Appendices.
Using Abstraction to Manage Complexity Abstraction: procedural abstraction & data abstraction. Procedural abstraction=> function development should separate.
Guidelines for working with Microsoft Visual Studio.Net.
Chapter 6. 2 Objectives You should be able to describe: Function and Parameter Declarations Returning a Single Value Pass by Reference Variable Scope.
CS 201 Functions Debzani Deb.
Guidelines for working with Microsoft Visual Studio 6.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 13 - The Preprocessor Outline 13.1Introduction.
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.
1 CSE 303 Lecture 13b The C preprocessor reading: Programming in C Ch. 13 slides created by Marty Stepp
C How to Program, 6/e © by Pearson Education, Inc. All Rights Reserved.
 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.
chap13 Chapter 13 Programming in the Large.
A First Book of C++: From Here To There, Third Edition2 Objectives You should be able to describe: Function and Parameter Declarations Returning a Single.
Macros. There are three basic phases for C programming. preprocessing, compiling, and linking. C input file is first passed to a preprocessing program.
Chapter 13 Programming in the Large Dr. Jiung-yao Huang Dept. Comm. Eng. Nat. Chung Cheng Univ. TA: 鄭筱親 陳昱豪.
© 2010 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Chapter 13: Programming in the Large Problem Solving & Program Design.
 2007 Pearson Education, Inc. All rights reserved C Functions -Continue…-
Computer Programming I Hour 2 - Writing Your First C Program.
C Hints and Tips The preprocessor and other fun toys.
Fundamentals of C and C++ Programming. EEL 3801 – Lotzi Bölöni Sub-Topics  Basic Program Structure  Variables - Types and Declarations  Basic Program.
CPS120: Introduction to Computer Science Lecture 14 Functions.
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.
C Functions Three major differences between C and Java functions: –Functions are stand-alone entities, not part of objects they can be defined in a file.
CPS4200 Unix Systems Programming Chapter 2. Programs, Processes and Threads A program is a prepared sequence of instructions to accomplish a defined task.
Operating Systems Process Creation
 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 ICS103 Programming in C Lecture 8: Functions I.
Chapter 12: Programming in the Large By: Suraya Alias 1-1.
The Preprocessor Directives Introduction Preprocessing – Occurs before program compiled Inclusion of external files Definition of symbolic constants.
+ Storage Classes and Linkage. + Introduction Scope describe the region or regions of a program that can access and identifier Variables can be shared.
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.
Building Programs from Existing Information Solutions for programs often can be developed from previously solved problems. Data requirements and solution.
Revisiting building. Preprocessing + Compiling 2 Creates an object file for each code file (.c ->.o) Each.o file contains code of the functions and structs.
Pre-Compiler Directives for TTCN-3 Ina Schieferdecker in response to CR5089 and 5090.
Unit 10 Code Reuse. Key Concepts Abstraction Header files Implementation files Storage classes Exit function Conditional compilation Command-line arguments.
13 C Preprocessor.
C++ Lesson 1.
Functions Students should understand the concept and basic mechanics of the function call/return pattern from CS 1114/2114, but some will not. A function.
UMBC CMSC 104 – Section 01, Fall 2016
Stack and Heap Memory Stack resident variables include:
User-Written Functions
Chapter 6 CS 3370 – C++ Functions.
INC 161 , CPE 100 Computer Programming
Protection of System Resources
Chapter 13 - The Preprocessor
C Basics.
Programmazione I a.a. 2017/2018.
Pre-processor Directives
Instructor: Ioannis A. Vetsikas
Chapter 5 - Functions Outline 5.1 Introduction
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).
Preprocessor.
Govt. Polytechnic,Dhangar
Programming in C Miscellaneous Topics.
Programming in C Miscellaneous Topics.
C Preprocessor Seema Chandak.
Conditional Compilation
CPS125.
ENERGY 211 / CME 211 Lecture 29 December 3, 2008.
SPL – PS1 Introduction to C++.
Presentation transcript:

CISC105 – General Computer Science Class 18 – 08/02/2006

#1 Reason to use Libraries Code REUSE! If the code is specific to solving a specific problem chances are you will not need libraries

Functions in Personal Libraries When developing a personal library you should make the functions as general as possible. Look to variables to see if they are needed or if they should be included as input variables.

Functions in Personal Libraries Limitations of the functions should be known and tested for so a program can terminate gracefully Graceful termination is always preferable to corrupt data! Use of the exit() function in a library can be used to gracefully exit a program See my_math.h, my_math.c and my_math_test.c

The exit command exit will terminate the run of a program and as such should be used with caution! Avoid using exit(0) as this will indicate a normal termination of the program. Only use exit(1) when error recovery is not possible or useful

Review When is it a good idea to request a storage class of register? static? const? What are the two types of files that we need to define a library? Why do we need to #include the header file of a library in the libraries implementation file?

Conditional Compilation The C preprocessor recognizes commands that allow the user to select parts of a program to be compiled or omitted. We can add debugging printf statements in a program and can choose to compile using the statements or to omit them See my_math_test2.c

Conditional Compilation We can also use Conditional Compilation to define what library to use to avoid duplicate declarations Conditional Compilation statements can be used for OS specific statements in code (#define WINDOWS or #define UNIX) #if defined (WINDOWS) statements #elif defined (UNIX) statements #else statements #endif

More command line arguments What are the 2 variables that we need to include in our main declaration in order to accept command line arguments? What does int argc tell us? What does char *argv[] tell us? See command_line1.c

Macros A macro is a facility for naming a commonly used statement or operation. We define a macro by using the #define preprocessor command Macros can take parameters macro expansion is the process of replacing a macro call by its meaning See macro1.c

Macros Is macro just another name for a function? Macros differ from functions in that they do not require allocation and deallocation Macro code is evaluated during preprocessing and the code is expanded Watch out for ()!!! Improper placement of parentheses can lead to improper execution See macro2.c

Questions Questions about anything we have gone over today? Questions about anything related to Programming in C? Questions about the Lab/Project?