Comments, Prototypes, Headers & Multiple Source Files

Slides:



Advertisements
Similar presentations
Chapter 11 Separate Compilation and Namespaces. Copyright © 2006 Pearson Addison-Wesley. All rights reserved Learning Objectives Separate Compilation.
Advertisements

Copyright © 2002 Pearson Education, Inc. Slide 1.
Chapter 12 Separate Compilation and Namespaces. Abstract Data Type (ADT) ADT: A data type consisting of data and their behavior. The abstraction is that.
CSc 352 An Introduction to the C Preprocessor Saumya Debray Dept. of Computer Science The University of Arizona, Tucson
Chapter 11 Separate Compilation and Namespaces Copyright © 2008 Pearson Addison-Wesley. All rights reserved.
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 12A Separate Compilation and Namespaces For classes this time.
Chapter 10 More on Modular Programming and Functions.
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
© 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.
CS201 – C Functions Procedural Abstraction Code Reuse C Library.
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 Programming Using C Modularity. 2 Contents Modularity Functions Preprocessor Comments Global variables.
Multiple Files. Monolithic vs Modular  one file before  system includes  main driver function  prototypes  function.
COMPUTER PROGRAMMING. A Typical C++ Environment Phases of C++ Programs: 1- Edit 2- Preprocess 3- Compile 4- Link 5- Load 6- Execute Loader Primary Memory.
Computer Programming I Hour 2 - Writing Your First C Program.
Fundamentals of C and C++ Programming. EEL 3801 – Lotzi Bölöni Sub-Topics  Basic Program Structure  Variables - Types and Declarations  Basic Program.
Separating Definition & Implementation Headers and Comments.
Compilation & Linking Computer Organization I 1 November 2009 © McQuain, Feng & Ribbens The Preprocessor When a C compiler is invoked, the.
L function n predefined, programmer-defined l arguments, (formal) parameters l return value l function call, function invocation l function definition.
1 CHAPTER 3 MODULAR PROGRAMMING. 2 Introduction  A library in C is a collection of general purpose and related functions.  2 types of libraries: Standard.
Lecture 13: Working with Multiple Programmers. Headers Header files: Each standard library has a corresponding header. The function prototype for all.
CSCI 171 Presentation 6 Functions and Variable Scope.
DOCUMENTATION SECTION GLOBAL DECLARATION SECTION
MODULAR ORGANIZATION Prepared by MMD, Edited by MSY1.
15. WRITING LARGE PROGRAMS. Source Files A program may be divided into any number of source files. Source files have the extension.c by convention. Source.
Separate Compilation Bryce Boe 2013/10/09 CS24, Fall 2013.
Chapter 9 Separate Compilation and Namespaces. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. Slide 2 Overview Separate Compilation (9.1)
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 12 Separate Compilation and Namespaces.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 12 Separate Compilation and Namespaces.
Lecture-3 Functions and Recursion. C Preprocessor Includes header files like stdio.h Expands macros defined Handles conditional compilations PreprocessorProcessor.
Program in Multiple Files. l all C++ statements are divided into executable and non-executable l executable - some corresponding machine code is generated.
Classes Classes are a major feature of C++. They support – – Abstraction – Data hiding – Encapsulation – Modularity – Re-use through inheritance.
Problem Session 4 Header Files and Unix. Where are they? You may need to examine the header file to determine what the data structures and functions provided.
Defining Data Types in C++ Part 2: classes. Quick review of OOP Object: combination of: –data structures (describe object attributes) –functions (describe.
Object Access m1.write(44); m2.write(m2.read() +1); std::cout
1 CS 192 Lecture 4 Winter 2003 December 8-9, 2003 Dr. Shafay Shamail.
Appendix 1 - Packages Jim Fawcett copyright (c)
Automatic Documentation Systems
What Is? function predefined, programmer-defined
Compilation and Debugging
Separate Compilation and Namespaces
A First C++ Class – a Circle
Chapter 13 - The Preprocessor
C Language By Sra Sontisirikit
Advanced UNIX progamming
Functions Separate Compilation
The Preprocessor Based on Chapter 1 in C++ for Java Programmers by Weiss When a C compiler is invoked, the first thing that happens is that the code is.
Pre-processor Directives
C++ Classes C++ Interlude 1.
Preprocessor C program → Modified C program → Object Code
Separate Compilation and Namespaces
Basic C++ What’s a declaration? What’s a definition?
C Preprocessor(CPP).
Separating Definition & Implementation
Class Commenting Doxygen for Classes.
Introduction to Classes and Objects
CSc 352 An Introduction to the C Preprocessor
Code Organization CSCE 121 J. Michael Moore.
Classes.
C++ Compilation Model C++ is a compiled language
A programming language
C Programming Language
What Is? function predefined, programmer-defined
Chapter 11 Class Inheritance
Executable program (p1)
Lecture 8 Object Oriented Programming (OOP)
SPL – PS1 Introduction to C++.
Presentation transcript:

Comments, Prototypes, Headers & Multiple Source Files Modular Code Comments, Prototypes, Headers & Multiple Source Files

Comments Functions designed to: Be reused Be an abstraction Function comments preserve the abstraction "OK, how do I use this thing?"

Doxygen Format Put /** block comment before function: @brief Description of function. @param NAME what parameter called NAME is for @return What is returned

Review Structured comments Used for: Machine readable Automatic documentation Tooltips in IDE?

Function Prototypes Function Prototype : Function header with no body (followed by ;) Declares a function

Prototypes Can use a declared function even if not defined yet Not needed until linking is done

Function Libraries & Headers Function Library : Collection of functions for use elsewhere in program Header files Place to store high level definitions for a code library Should not have code, just declarations .h extension

Compilation Header tells each file functions exist Code in .cpp so that only one definition is compiled

Finding headers Include with < > looks in compiler defined directories Include with " " looks in your project, then regular directories

Guards Don't want same definitions included twice Preprocessor guard: Easy to do by accident: Include A and B, B also includes A Preprocessor guard: #ifndef : if this symbol not defined, read until #endif #define : define a symbol HELPERS_H made up should be unique