CAAM 420 Fall 2012 Lecture 15. Roman Schutski

Size: px
Start display at page:

Download "CAAM 420 Fall 2012 Lecture 15. Roman Schutski"

Transcription

1 CAAM 420 Fall 2012 Lecture 15 Roman Schutski December 2, 2012

2 Table of Contents 1 Using make. Structures Makefiles Syntax Simple example Wildcards and suffixes Generic Makefile Structures Syntax Constructor/Destructor Handling structures in a clever way

3 1. Using make. Structures. 1.1 Makefiles Syntax The larger the program becomes, the more code is needed to be reused. One can put all of the code into a monolithic file, but soon it will become difficult to maintain and modify, especially when a lot of people work on the same project. Then the code is usually split to a bunch of short.c and.h files, but in this case the recompilation of the whole project becomes tricky. That s when Makefiles can come to help. Makefile is an input file for the program make. For more information see [1]. Provided with a Makefile, make is looking for targets in it, and performs actions defined for each target. Targets can have dependencies. In this case make processes each of the dependencies (and any subsequent dependencies) in order to process a target. Make is also smart enougth to find out that some objects haven t changed and don t need to be processed. This way one can compile the whole project by simply typing make. The syntax of a Makefile is: 1 # comments 2 variables = values 3 target1 : dependencies 4 command 5 target2 : dependencies 6 command Note that commands are started by the < T ab > whitespace Simple example A trivial example is here: 1 CC = gcc 2 3 all : hello 4 hello : hello.o 5 $(CC) $( CFLAGS ) hello.o -o hello 6 hello.o: hello.c 7 $(CC) $( CFLAGS ) -c hello.c 8 clean : 9 rm - f hello hello. o In this example in order to process the target all make first looks for hello, then for hello.o (to link hello). In case it doesn t present or hello.c changed, the compilation of the hello.o is triggered. Also there is a target clean that removes old executables. To activate it just type make clean. By default, the first target in the list is called, in this case it is all. 3

4 1.1.3 Wildcards and suffixes To write shorter Makefiles and keep track of filenames automatically wildcards are used. Consider the next example. 1 CC = gcc 2 SOURCES = hello.c 3 OBJECTS =$( SOURCES :.c=.o) 4 5 all : hello $( SOURCES ) 6 hello : $( OBJECTS ) 7 $(CC) $( OBJECTS ) -o $@ 8.c.o: 9 $(CC) $< -o $@ 10 clean : 11 rm - f hello hello. o Above the wildcard.o.c tells that for each file with suffix.c the corresponding file with suffix.o should be created. Also, the expression.c=.o tells make that the variable OBJECTS is the same as sources, except that each suffix.c is replaced by.o Generic Makefile The knowledge of writing Makefiles is useful, but not always required. Often it s sufficient just to pick up a working one. Here it is: 1 # Compiler / linker 2 CC=gcc 3 LD=gcc 4 # Compile flags ( debug on, include all libs ) 5 CFLAGS =-c -Wall -g 6 # Link flags 7 LDFLAGS =-g -Wall 8 # Include path ( in case you have some. h files ) 9 INCLUDE =./ 10 # Sources to compile ( Add your stuff here :) 11 SOURCES = main. c function. c otherfunction. c 12 OBJECTS =$( SOURCES :.c=.o) 13 # Produced executable name 14 EXECUTABLE = testprog all : $( SOURCES ) $( EXECUTABLE ) $( EXECUTABLE ): $( OBJECTS ) 19 $(LD) $( LDFLAGS ) $( OBJECTS ) -o $@ 20.c.o: 4

5 21 $(CC) $( CFLAGS ) -I$( INCLUDE ) $< -o $@ 22 # additional actions ( not objects ) 23 clean : 24 rm -rf $( OBJECTS ) Just put it in the folder of with your project. You only need to adjust variables. EXE- CUTABLE - the name of the resulting program. SOURCES - a list of your sourcefiles. 1.2 Structures Syntax Structures are variables that contain a set of other variables.[2] They are primarily used to organize data in a convenient way. Consider the next example of a multidimensional vector: 1 # ifndef VECTOR 2 # define VECTOR 3 4 typedef struct { 5 int size ; 6 double * elem ; 7 } vector ; 8 9 # endif The keyword for defining structures is struct. Then the elements of the structure are listed in curly brackets. At the end of the brackets the name of the structure comes. Here we used a keyword typedef to define the name of the structure as a new type of data. To use this just include the header file into your source code adding 1 # include " vector.h" at the beginning of the.c file. Then it is possible to define a new entity of vector structure writing: 1 vector newvector ; 2 /* Without typedef it should be " struct vector newvector ;" */ To access elements of the structure the dot operator is used. Also, there is another useful operator >, that means dereference pointer to a structure and access it s elements. Consider the following example: 1 vector vec ; 2 vector * pt_vec ; 5

6 3 4 pt_vec = & vec ; 5 pt_vec - > size = 2; Here we changed an element size of vector vec through a pointer to vec. Passing pointers instead of structures themselves is a common practice, as structures can be huge and copying them can be memory-demanding and long Constructor/Destructor When we start dealing with structures, the first question is how to initialize them in a convenient way. It is possible to do it by hand, but if a structure has lot s of elements and pointers, this becomes awkward. The solution is to define a special function to deal with the initialization, that is called constructor. As a complement to it we can also define a function destructor to clean up the memory used by the structure. Then, we can put the prototypes of these functions along with the definition of the structure itself in the header file. For our example vector structure this will be vector.h: 1 # ifndef VECTOR 2 # define VECTOR 3 4 typedef struct { 5 int size ; 6 double * elem ; 7 } vector ; vector * vector_constructor ( int length ); 11 void vec tor_de struct or ( vector * vec ); 12 # endif vector.c: 1 # include " vector.h" 2 # include < stdlib.h> 3 4 vector * vector_constructor ( int size ){ 5 int i; 6 vector * newvec = calloc (1, sizeof ( vector )); 7 newvec -> size = size ; 8 newvec -> elem = ( double *) calloc (size, sizeof ( double )); 9 /* initialize elements with zeros */ 10 for (i =0;i< length ;i ++) 11 newvec -> elem [i] = 0; 12 return newvec ; 6

7 13 } void vec tor_de struct or ( vector * vec ){ 16 free (vec -> elem ); 17 free ( vec ); 18 } vector constructor() allocates memory for new entity of vector and returns a pointer to it. vector destructor() cleans up everything. Then, it simple to create vectors in the code: 1 int vecsize ; 2 vector * somevect = vector_constructor (3) ; 3 // do something useful, like 4 vecsize = somevect - > size ; 5 vector_destructor ( somevect ); Handling structures in a clever way First, it s useful to give meaningful names for the elements of the structure, especially if the structure is big. If some element is used too much times it s wize to create a separate function to retrieve it s value. In case of vector, we can define a function vector length() and put it s prototype to vector.h: 1 int vector_length ( vector * vec ); And the implementation of the vector length() function to vector.c: 1 int vector_length ( vector * vec ){ 2 int lenght ; 3 length = vec -> size ; 4 return length ; 5 } Putting prototypes of all functions that deal with the elements of the structure along with the structure itself in the same header file is a useful practice. Then, one can just include that header to his/her own source code and receive all the functionality of the structure in any place of the program. Additionaly, using such access functions minimizes the risk of memory access errors. Other useful functions for vectors may be vector set(), vector get(). Their implementatoin is included. 7

8 Bibliography [1] Gnu make homepage. [2] Brian W. Kernighan and Dennis M. Ritchie. The C Programming Language (2nd edition). Prentice Hall Software Series,

Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 2

Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 2 Compiling a C program CS Basics 15) Compiling a C prog. Emmanuel Benoist Fall Term 2016-17 Example of a small program Makefile Define Variables Compilation options Conclusion Berner Fachhochschule Haute

More information

CS Basics 15) Compiling a C prog.

CS Basics 15) Compiling a C prog. CS Basics 15) Compiling a C prog. Emmanuel Benoist Fall Term 2016-17 Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 1 Compiling a C program Example of a small

More information

Deep C. Multifile projects Getting it running Data types Typecasting Memory management Pointers. CS-343 Operating Systems

Deep C. Multifile projects Getting it running Data types Typecasting Memory management Pointers. CS-343 Operating Systems Deep C Multifile projects Getting it running Data types Typecasting Memory management Pointers Fabián E. Bustamante, Fall 2004 Multifile Projects Give your project a structure Modularized design Reuse

More information

CS2141 Software Development using C/C++ Compiling a C++ Program

CS2141 Software Development using C/C++ Compiling a C++ Program CS2141 Software Development using C/C++ Compiling a C++ Program g++ g++ is the GNU C++ compiler. A program in a file called hello.cpp: #include using namespace std; int main( ) { cout

More information

Reliable C++ development - session 1: From C to C++ (and some C++ features)

Reliable C++ development - session 1: From C to C++ (and some C++ features) Reliable C++ development - session 1: From C to C++ (and some C++ features) Thibault CHOLEZ - thibault.cholez@loria.fr TELECOM Nancy - Université de Lorraine LORIA - INRIA Nancy Grand-Est From Nicolas

More information

Makefile Tutorial. Eric S. Missimer. December 6, 2013

Makefile Tutorial. Eric S. Missimer. December 6, 2013 Makefile Tutorial Eric S. Missimer December 6, 2013 1 Basic Elements of a Makefile 1.1 Explicit Rules A the major part of a Makefile are the explicit rules (a.k.a. recipes) that make certain files. Below

More information

INTERMEDIATE SOFTWARE DESIGN SPRING 2011 ACCESS SPECIFIER: SOURCE FILE

INTERMEDIATE SOFTWARE DESIGN SPRING 2011 ACCESS SPECIFIER: SOURCE FILE HEADER FILE A header (.h,.hpp,...) file contains Class definitions ( class X {... }; ) Inline function definitions ( inline int get_x() {... } ) Function declarations ( void help(); ) Object declarations

More information

Projects and Make Files

Projects and Make Files Projects and Make Files Creating an executable file requires compiling the source code into an object* file (file.o) and then linking that file with (other files and) libraries to create the executable

More information

Maemo Diablo GNU Make and makefiles Training Material

Maemo Diablo GNU Make and makefiles Training Material Maemo Diablo GNU Make and makefiles Training Material February 9, 2009 Contents 1 GNU Make and makefiles 2 1.1 What is GNU Make?......................... 2 1.2 How does make work?........................

More information

CS 107 Lecture 18: GCC and Make

CS 107 Lecture 18: GCC and Make S 107 Lecture 18: G and Make Monday, March 12, 2018 omputer Systems Winter 2018 Stanford University omputer Science Department Lecturers: Gabbi Fisher and hris hute Today's Topics 1. What really happens

More information

CS11 Intro C++ Spring 2018 Lecture 4

CS11 Intro C++ Spring 2018 Lecture 4 CS11 Intro C++ Spring 2018 Lecture 4 Build Automation When a program grows beyond a certain size, compiling gets annoying g++ -std=c++14 -Wall units.cpp testbase.cpp \ hw3testunits.cpp -o hw3testunits

More information

CSCI-243 Exam 2 Review February 22, 2015 Presented by the RIT Computer Science Community

CSCI-243 Exam 2 Review February 22, 2015 Presented by the RIT Computer Science Community CSCI-43 Exam Review February, 01 Presented by the RIT Computer Science Community http://csc.cs.rit.edu C Preprocessor 1. Consider the following program: 1 # include 3 # ifdef WINDOWS 4 # include

More information

Programs. Function main. C Refresher. CSCI 4061 Introduction to Operating Systems

Programs. Function main. C Refresher. CSCI 4061 Introduction to Operating Systems Programs CSCI 4061 Introduction to Operating Systems C Program Structure Libraries and header files Compiling and building programs Executing and debugging Instructor: Abhishek Chandra Assume familiarity

More information

CS11 Advanced C++ Fall Lecture 4

CS11 Advanced C++ Fall Lecture 4 CS11 Advanced C++ Fall 2006-2007 Lecture 4 Today s Topics Using make to automate build tasks Using doxygen to generate API docs Build-Automation Standard development cycle: Write more code Compile Test

More information

CMPSC 311- Introduction to Systems Programming Module: Build Processing

CMPSC 311- Introduction to Systems Programming Module: Build Processing CMPSC 311- Introduction to Systems Programming Module: Build Processing Professor Patrick McDaniel Fall 2014 UNIX Pipes Pipes are ways of redirecting the output of one command to the input of another Make

More information

2 Compiling a C program

2 Compiling a C program 2 Compiling a C program This chapter describes how to compile C programs using gcc. Programs can be compiled from a single source file or from multiple source files, and may use system libraries and header

More information

CSE 374 Programming Concepts & Tools

CSE 374 Programming Concepts & Tools CSE 374 Programming Concepts & Tools Hal Perkins Fall 2017 Lecture 14 Makefiles and Compilation Management 1 Where we are Onto tools... Basics of make, particular the concepts Some fancier make features

More information

C++ PROGRAMMING LANGUAGE: CLASSES. CAAM 519, CHAPTER 13

C++ PROGRAMMING LANGUAGE: CLASSES. CAAM 519, CHAPTER 13 C++ PROGRAMMING LANGUAGE: CLASSES. CAAM 519, CHAPTER 13 This chapter focuses on introducing the notion of classes in the C++ programming language. We describe how to create class and use an object of a

More information

CSCI 2132 Software Development. Lecture 29: Dynamic Memory Allocation

CSCI 2132 Software Development. Lecture 29: Dynamic Memory Allocation CSCI 2132 Software Development Lecture 29: Dynamic Memory Allocation Instructor: Vlado Keselj Faculty of Computer Science Dalhousie University 22-Nov-2017 (29) CSCI 2132 1 Previous Lecture Protecting header

More information

CSC 2500: Unix Lab Fall 2016

CSC 2500: Unix Lab Fall 2016 CSC 2500: Unix Lab Fall 2016 Makefile Mohammad Ashiqur Rahman Department of Computer Science College of Engineering Tennessee Tech University Agenda Make Utility Build Process The Basic Makefile Target

More information

CPSC 427: Object-Oriented Programming

CPSC 427: Object-Oriented Programming CPSC 427: Object-Oriented Programming Michael J. Fischer Lecture 3 September 7, 2016 CPSC 427, Lecture 3 1/27 Insertion Sort Example Program specification Monolithic solution Modular solution in C Modular

More information

JTSK Programming in C II C-Lab II. Lecture 3 & 4

JTSK Programming in C II C-Lab II. Lecture 3 & 4 JTSK-320112 Programming in C II C-Lab II Lecture 3 & 4 Xu (Owen) He Spring 2018 Slides modified from Dr. Kinga Lipskoch Planned Syllabus The C Preprocessor Bit Operations Pointers and Arrays (Dynamically

More information

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 12, FALL 2012

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 12, FALL 2012 CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 12, FALL 2012 TOPICS TODAY Assembling & Linking Assembly Language Separate Compilation in C Scope and Lifetime LINKING IN ASSEMBLY

More information

CMPSC 311- Introduction to Systems Programming Module: Build Processing

CMPSC 311- Introduction to Systems Programming Module: Build Processing CMPSC 311- Introduction to Systems Programming Module: Build Processing Professor Patrick McDaniel Fall 2016 UNIX Pipes Pipes are ways of redirecting the output of one command to the input of another Make

More information

PRINCIPLES OF OPERATING SYSTEMS

PRINCIPLES OF OPERATING SYSTEMS PRINCIPLES OF OPERATING SYSTEMS Tutorial-1&2: C Review CPSC 457, Spring 2015 May 20-21, 2015 Department of Computer Science, University of Calgary Connecting to your VM Open a terminal (in your linux machine)

More information

COMP1917: Computing 1 1. Introduction

COMP1917: Computing 1 1. Introduction COMP1917: Computing 1 1. Introduction Reading: Moffat, Chapter 1. COMP1917 12s2 Introduction 1 Course Web Site http://www.cse.unsw.edu.au/~cs1917/12s2 Please check this Web Site regularly for updated information,

More information

Overview of today s lecture. Quick recap of previous C lectures. Introduction to C programming, lecture 2. Abstract data type - Stack example

Overview of today s lecture. Quick recap of previous C lectures. Introduction to C programming, lecture 2. Abstract data type - Stack example Overview of today s lecture Introduction to C programming, lecture 2 -Dynamic data structures in C Quick recap of previous C lectures Abstract data type - Stack example Make Refresher: pointers Pointers

More information

COMP1917: Computing 1 1. Introduction

COMP1917: Computing 1 1. Introduction COMP1917: Computing 1 1. Introduction Reading: Moffat, Chapter 1. COMP1917 15s2 Introduction 1 Course Web Site http://www.cse.unsw.edu.au/~cs1917/15s2 Please check this Web Site regularly for updated information,

More information

1. Introduction. Course Web Site. COMP1917: Computing 1. Textbook. Occupational Health and Safety (OHS)

1. Introduction. Course Web Site. COMP1917: Computing 1. Textbook. Occupational Health and Safety (OHS) COMP1917 14s2 Introduction 1 COMP1917: Computing 1 1. Introduction Reading: Moffat, Chapter 1. Course Web Site http://www.cse.unsw.edu.au/~cs1917/14s2 Please check this Web Site regularly for updated information,

More information

Topic 6: A Quick Intro To C

Topic 6: A Quick Intro To C Topic 6: A Quick Intro To C Assumption: All of you know Java. Much of C syntax is the same. Also: Many of you have used C or C++. Goal for this topic: you can write & run a simple C program basic functions

More information

Computer Science 322 Operating Systems Mount Holyoke College Spring Topic Notes: C and Unix Overview

Computer Science 322 Operating Systems Mount Holyoke College Spring Topic Notes: C and Unix Overview Computer Science 322 Operating Systems Mount Holyoke College Spring 2010 Topic Notes: C and Unix Overview This course is about operating systems, but since most of our upcoming programming is in C on a

More information

UNIX Makefile. C Project Library Distribution and Installation.

UNIX Makefile. C Project Library Distribution and Installation. UNIX Makefile C Project Library Distribution and Installation. Tarballs Most non-package software is distributed in source code format. The most common format being C project libraries in compressed TAR

More information

CSE 374 Programming Concepts & Tools. Hal Perkins Fall 2015 Lecture 19 Introduction to C++

CSE 374 Programming Concepts & Tools. Hal Perkins Fall 2015 Lecture 19 Introduction to C++ CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 19 Introduction to C++ C++ C++ is an enormous language: All of C Classes and objects (kind of like Java, some crucial differences) Many

More information

C Programming Helper. Prof Bill - Mar This is a little helper document for quickly plunging into the C Programming Language.

C Programming Helper. Prof Bill - Mar This is a little helper document for quickly plunging into the C Programming Language. C Programming Helper Prof Bill - Mar 2018 This is a little helper document for quickly plunging into the C Programming Language. The sections are: A. Introduction B. The Command Line C. C Coding D. My

More information

Continue: How do I learn C? C Primer Continued (Makefiles, debugging, and more ) Last Time: A Simple(st) C Program 1-hello-world.c!

Continue: How do I learn C? C Primer Continued (Makefiles, debugging, and more ) Last Time: A Simple(st) C Program 1-hello-world.c! Continue: How do I learn C? C Primer Continued (Makefiles, debugging, and more ) Hello Word! ~/ctest/ In addition to syntax you need to learn: the Tools the Libraries. And the Documentation. Maria Hybinette,

More information

Makefiles are a simple way to organize code compilation. Using a makefile it is possible to compile several source files to produce an executable;

Makefiles are a simple way to organize code compilation. Using a makefile it is possible to compile several source files to produce an executable; Makefile Makefiles are a simple way to organize code compilation. Using a makefile it is possible to compile several source files to produce an executable; Source (.cc) and header (.h) files can be placed

More information

Workshop Agenda Feb 25 th 2015

Workshop Agenda Feb 25 th 2015 Workshop Agenda Feb 25 th 2015 Time Presenter Title 09:30 T. König Talk bwhpc Concept & bwhpc-c5 - Federated User Support Activities 09:45 R. Walter Talk bwhpc architecture (bwunicluster, bwforcluster

More information

Oregon State University School of Electrical Engineering and Computer Science. CS 261 Recitation 1. Spring 2011

Oregon State University School of Electrical Engineering and Computer Science. CS 261 Recitation 1. Spring 2011 Oregon State University School of Electrical Engineering and Computer Science CS 261 Recitation 1 Spring 2011 Outline Using Secure Shell Clients GCC Some Examples Intro to C * * Windows File transfer client:

More information

The make utility automatically determines which pieces of a large program need to be recompiled, and issues commands to recompile them.

The make utility automatically determines which pieces of a large program need to be recompiled, and issues commands to recompile them. What is make? 1 make is a system utility for managing the build process (compilation/linking/etc). There are various versions of make; these notes discuss the GNU make utility included on Linux systems.

More information

Make! CSC230: C and Software Tools. N.C. State Department of Computer Science. Some examples adapted from

Make! CSC230: C and Software Tools. N.C. State Department of Computer Science. Some examples adapted from Make! CSC230: C and Software Tools N.C. State Department of Computer Science Some examples adapted from http://mrbook.org/tutorials/make/ CSC230: C and Software Tools NC State University Computer Science

More information

Computer Science 2500 Computer Organization Rensselaer Polytechnic Institute Spring Topic Notes: C and Unix Overview

Computer Science 2500 Computer Organization Rensselaer Polytechnic Institute Spring Topic Notes: C and Unix Overview Computer Science 2500 Computer Organization Rensselaer Polytechnic Institute Spring 2009 Topic Notes: C and Unix Overview This course is about computer organization, but since most of our programming is

More information

CSE 333 Interlude - make and build tools

CSE 333 Interlude - make and build tools CSE 333 Interlude - make and build tools Hal Perkins Paul G. Allen School of Computer Science & Engineering University of Washington make make is a classic program for controlling what gets (re)compiled

More information

the gamedesigninitiative at cornell university Lecture 7 C++ Overview

the gamedesigninitiative at cornell university Lecture 7 C++ Overview Lecture 7 Lecture 7 So You Think You Know C++ Most of you are experienced Java programmers Both in 2110 and several upper-level courses If you saw C++, was likely in a systems course Java was based on

More information

CSci 4061 Introduction to Operating Systems. Programs in C/Unix

CSci 4061 Introduction to Operating Systems. Programs in C/Unix CSci 4061 Introduction to Operating Systems Programs in C/Unix Today Basic C programming Follow on to recitation Structure of a C program A C program consists of a collection of C functions, structs, arrays,

More information

Kurt Schmidt. October 30, 2018

Kurt Schmidt. October 30, 2018 to Structs Dept. of Computer Science, Drexel University October 30, 2018 Array Objectives to Structs Intended audience: Student who has working knowledge of Python To gain some experience with a statically-typed

More information

Entity vs. Value, Modules, Hidden Implementation, Interface Specification

Entity vs. Value, Modules, Hidden Implementation, Interface Specification Entity vs. Value, Modules, Hidden Implementation, Interface Specification CS 247 University of Waterloo cs247@uwaterloo.ca May 19, 2017 CS 247 (UW) Tutorial 3 May 19, 2017 1 / 24 Overview 1 Move Constructors,

More information

C Coding standard. Raphael kena Poss. July Introduction 2. 3 File system layout 2

C Coding standard. Raphael kena Poss. July Introduction 2. 3 File system layout 2 C Coding standard Raphael kena Poss July 2014 Contents 1 Introduction 2 2 Systems programming @ VU Amsterdam 2 3 File system layout 2 4 Code style 3 4.1 Comments and preprocessor.................................

More information

NEXT SET OF SLIDES FROM DENNIS FREY S FALL 2011 CMSC313.

NEXT SET OF SLIDES FROM DENNIS FREY S FALL 2011 CMSC313. NEXT SET OF SLIDES FROM DENNIS FREY S FALL 2011 CMSC313 http://www.csee.umbc.edu/courses/undergraduate/313/fall11/" C Programming Functions Program Organization Separate Compilation Functions vs. Methods

More information

Topic 6: A Quick Intro To C. Reading. "goto Considered Harmful" History

Topic 6: A Quick Intro To C. Reading. goto Considered Harmful History Topic 6: A Quick Intro To C Reading Assumption: All of you know basic Java. Much of C syntax is the same. Also: Some of you have used C or C++. Goal for this topic: you can write & run a simple C program

More information

Make: a build automation tool

Make: a build automation tool Make: a build automation tool What is the problem? The lab examples repository for the CS 253 course has 228 files in 54 folders. To build them all would requires us to navigate to 54 folders and compile

More information

CIS 190: C/C++ Programming. Lecture 2 Pointers and More

CIS 190: C/C++ Programming. Lecture 2 Pointers and More CIS 190: C/C++ Programming Lecture 2 Pointers and More Separate Compilation to prevent the file containing main() from getting too crowded and long function prototypes in their own file (functions.h) function

More information

CSE 333 Lecture 6 - data structures

CSE 333 Lecture 6 - data structures CSE 333 Lecture 6 - data structures Hal Perkins Department of Computer Science & Engineering University of Washington Administrivia Exercises: - ex5 is out: clean up the code from section yesterday, split

More information

CS240: Programming in C. Lecture 2: Overview

CS240: Programming in C. Lecture 2: Overview CS240: Programming in C Lecture 2: Overview 1 Programming Model How does C view the world? Stack Memory code Globals 2 Programming Model Execution mediated via a stack function calls and returns local

More information

cc is really a front-end program to a number of passes or phases of the whole activity of "converting" our C source files to executable programs:

cc is really a front-end program to a number of passes or phases of the whole activity of converting our C source files to executable programs: 1 next CITS2002 CITS2002 schedule What is cc really doing - the condensed version We understand how cc works in its simplest form: we invoke cc on a single C source file, we know the C-processor is invoked

More information

the gamedesigninitiative at cornell university Lecture 6 C++: Basics

the gamedesigninitiative at cornell university Lecture 6 C++: Basics Lecture 6 C++: Basics So You Think You Know C++ Most of you are experienced Java programmers Both in 2110 and several upper-level courses If you saw C++, was likely in a systems course Java was based on

More information

Reviewing gcc, make, gdb, and Linux Editors 1

Reviewing gcc, make, gdb, and Linux Editors 1 Reviewing gcc, make, gdb, and Linux Editors 1 Colin Gordon csgordon@cs.washington.edu University of Washington CSE333 Section 1, 3/31/11 1 Lots of material borrowed from 351/303 slides Colin Gordon (University

More information

Welcome to... CS113: Introduction to C

Welcome to... CS113: Introduction to C Welcome to... CS113: Introduction to C Instructor: Erik Sherwood E-mail: wes28@cs.cornell.edu Course Website: http://www.cs.cornell.edu/courses/cs113/2005fa/ The website is linked to from the courses page

More information

Programming in C S c o t t S c h r e m m e r

Programming in C S c o t t S c h r e m m e r Programming in C S c o t t S c h r e m m e r Outline Introduction Data Types and structures Pointers, arrays and dynamic memory allocation Functions and prototypes input/output comparisons compiling/makefiles/debugging

More information

CSE 333 Midterm Exam 5/9/14 Sample Solution

CSE 333 Midterm Exam 5/9/14 Sample Solution Question 1. (20 points) C programming. Implement the C library function strncpy. The specification of srncpy is as follows: Copy characters (bytes) from src to dst until either a '\0' character is found

More information

G52CPP C++ Programming Lecture 6. Dr Jason Atkin

G52CPP C++ Programming Lecture 6. Dr Jason Atkin G52CPP C++ Programming Lecture 6 Dr Jason Atkin 1 Last lecture The Stack Lifetime of local variables Global variables Static local variables const (briefly) 2 Visibility is different from lifetime Just

More information

Chris' Makefile Tutorial

Chris' Makefile Tutorial Chris' Makefile Tutorial Chris Serson University of Victoria June 26, 2007 Contents: Chapter Page Introduction 2 1 The most basic of Makefiles 3 2 Syntax so far 5 3 Making Makefiles Modular 7 4 Multi-file

More information

C Review. MaxMSP Developers Workshop Summer 2009 CNMAT

C Review. MaxMSP Developers Workshop Summer 2009 CNMAT C Review MaxMSP Developers Workshop Summer 2009 CNMAT C Syntax Program control (loops, branches): Function calls Math: +, -, *, /, ++, -- Variables, types, structures, assignment Pointers and memory (***

More information

How to learn C? CSCI [4 6]730: A C Refresher or Introduction. Diving In: A Simple C Program 1-hello-word.c

How to learn C? CSCI [4 6]730: A C Refresher or Introduction. Diving In: A Simple C Program 1-hello-word.c How to learn C? CSCI [4 6]730: A C Refresher or Introduction Hello Word! ~/ctutorial/ In addition to syntax you need to learn: the Tools. the Libraries. And the Documentation (how to access) Practice on

More information

EL2310 Scientific Programming

EL2310 Scientific Programming Lecture 7: Introduction to C (pronobis@kth.se) Overview Overview Lecture 7: Introduction to C Wrap Up Basic Datatypes and printf Branching and Loops in C Constant values Wrap Up Lecture 7: Introduction

More information

Make: a build automation tool 1/23

Make: a build automation tool 1/23 Make: a build automation tool 1/23 What is the problem? The lab examples repository for the CS 253 course has 293 files in 81 folders. To build them all would requires us to navigate to 81 folders and

More information

CSE 333. Lecture 11 - constructor insanity. Hal Perkins Paul G. Allen School of Computer Science & Engineering University of Washington

CSE 333. Lecture 11 - constructor insanity. Hal Perkins Paul G. Allen School of Computer Science & Engineering University of Washington CSE 333 Lecture 11 - constructor insanity Hal Perkins Paul G. Allen School of Computer Science & Engineering University of Washington Administrivia Exercises: - New exercise out today, due Monday morning

More information

Exercise Session 2 Systems Programming and Computer Architecture

Exercise Session 2 Systems Programming and Computer Architecture Systems Group Department of Computer Science ETH Zürich Exercise Session 2 Systems Programming and Computer Architecture Herbstsemester 216 Agenda Linux vs. Windows Working with SVN Exercise 1: bitcount()

More information

Makefiles SE 2XA3. Term I, 2018/19

Makefiles SE 2XA3. Term I, 2018/19 Makefiles SE 2XA3 Term I, 2018/19 Outline Example Calling make Syntax How it works Macros Suffix rules Command line options Example Assume we have files main.c, test.c, and lo.asm Consider the makefile

More information

Slide Set 5. for ENCM 339 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary

Slide Set 5. for ENCM 339 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary Slide Set 5 for ENCM 339 Fall 2016 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary October 2016 ENCM 339 Fall 2016 Slide Set 5 slide 2/32

More information

CS 137 Part 5. Pointers, Arrays, Malloc, Variable Sized Arrays, Vectors. October 25th, 2017

CS 137 Part 5. Pointers, Arrays, Malloc, Variable Sized Arrays, Vectors. October 25th, 2017 CS 137 Part 5 Pointers, Arrays, Malloc, Variable Sized Arrays, Vectors October 25th, 2017 Exam Wrapper Silently answer the following questions on paper (for yourself) Do you think that the problems on

More information

Exception Namespaces C Interoperability Templates. More C++ David Chisnall. March 17, 2011

Exception Namespaces C Interoperability Templates. More C++ David Chisnall. March 17, 2011 More C++ David Chisnall March 17, 2011 Exceptions A more fashionable goto Provides a second way of sending an error condition up the stack until it can be handled Lets intervening stack frames ignore errors

More information

C++ Style Guide. 1.0 General. 2.0 Visual Layout. 3.0 Indentation and Whitespace

C++ Style Guide. 1.0 General. 2.0 Visual Layout. 3.0 Indentation and Whitespace C++ Style Guide 1.0 General The purpose of the style guide is not to restrict your programming, but rather to establish a consistent format for your programs. This will help you debug and maintain your

More information

Tutorial: Compiling, Makefile, Parallel jobs

Tutorial: Compiling, Makefile, Parallel jobs Tutorial: Compiling, Makefile, Parallel jobs Hartmut Häfner Steinbuch Centre for Computing (SCC) Funding: www.bwhpc-c5.de Outline Compiler + Numerical Libraries commands Linking Makefile Intro, Syntax

More information

CMPT 115. C tutorial for students who took 111 in Java. University of Saskatchewan. Mark G. Eramian, Ian McQuillan CMPT 115 1/32

CMPT 115. C tutorial for students who took 111 in Java. University of Saskatchewan. Mark G. Eramian, Ian McQuillan CMPT 115 1/32 CMPT 115 C tutorial for students who took 111 in Java Mark G. Eramian Ian McQuillan University of Saskatchewan Mark G. Eramian, Ian McQuillan CMPT 115 1/32 Part I Starting out Mark G. Eramian, Ian McQuillan

More information

EL6483: Brief Overview of C Programming Language

EL6483: Brief Overview of C Programming Language EL6483: Brief Overview of C Programming Language EL6483 Spring 2016 EL6483 EL6483: Brief Overview of C Programming Language Spring 2016 1 / 30 Preprocessor macros, Syntax for comments Macro definitions

More information

CSE 374 Programming Concepts & Tools. Hal Perkins Spring 2010

CSE 374 Programming Concepts & Tools. Hal Perkins Spring 2010 CSE 374 Programming Concepts & Tools Hal Perkins Spring 2010 Lecture 19 Introduction ti to C++ C++ C++ is an enormous language: g All of C Classes and objects (kind of like Java, some crucial differences)

More information

EPITA SPE C Workshop - D0

EPITA SPE C Workshop - D0 EPITA SPE C Workshop - D0 marwan.burelle@lse.epita.fr http://www.lse.epita.fr Overview 1 B, PDP And Unics From Bell s Lab To ISO normalization 2 Imperative And Structured Syntax 3 Compilers Using make

More information

C Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

C Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee C Language Part 1 (Minor modifications by the instructor) References C for Python Programmers, by Carl Burch, 2011. http://www.toves.org/books/cpy/ The C Programming Language. 2nd ed., Kernighan, Brian,

More information

GDB and Makefile. Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

GDB and Makefile. Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island GDB and Makefile Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island GDB Debugging: An Example #include void main() { int i; int result

More information

Data and File Structures Laboratory

Data and File Structures Laboratory Tools: Gcov, Cscope, Ctags, and Makefiles Assistant Professor Machine Intelligence Unit Indian Statistical Institute, Kolkata August, 2018 1 Gcov 2 Cscope 3 Ctags 4 Makefiles Gcov Gcov stands for GNU Coverage

More information

Programming in C. What is C?... What is C?

Programming in C. What is C?... What is C? C Programming in C UVic SEng 265 Developed by Brian Kernighan and Dennis Ritchie of Bell Labs Earlier, in 1969, Ritchie and Thompson developed the Unix operating system We will be focusing on a version

More information

Programming in C UVic SEng 265

Programming in C UVic SEng 265 Programming in C UVic SEng 265 Daniel M. German Department of Computer Science University of Victoria 1 SEng 265 dmgerman@uvic.ca C Developed by Brian Kernighan and Dennis Ritchie of Bell Labs Earlier,

More information

CSE 333 Midterm Exam 7/29/13

CSE 333 Midterm Exam 7/29/13 Name There are 5 questions worth a total of 100 points. Please budget your time so you get to all of the questions. Keep your answers brief and to the point. The exam is closed book, closed notes, closed

More information

Programming in C. What is C?... What is C?

Programming in C. What is C?... What is C? Programming in C UVic SEng 265 C Developed by Brian Kernighan and Dennis Ritchie of Bell Labs Earlier, in 1969, Ritchie and Thompson developed the Unix operating system We will be focusing on a version

More information

Lab 4: Tracery Recursion in C with Linked Lists

Lab 4: Tracery Recursion in C with Linked Lists Lab 4: Tracery Recursion in C with Linked Lists For this lab we will be building on our previous lab at the end of the previous lab you should have had: #include #include char * make_string_from

More information

CS 261 Fall C Introduction. Variables, Memory Model, Pointers, and Debugging. Mike Lam, Professor

CS 261 Fall C Introduction. Variables, Memory Model, Pointers, and Debugging. Mike Lam, Professor CS 261 Fall 2017 Mike Lam, Professor C Introduction Variables, Memory Model, Pointers, and Debugging The C Language Systems language originally developed for Unix Imperative, compiled language with static

More information

CSE au Midterm Exam Nov. 2, 2018 Sample Solution

CSE au Midterm Exam Nov. 2, 2018 Sample Solution Question 1. (16 points) Build tools and make. We re building a C++ software back-end prototype for a new food web site. So far, we ve got the following source files with the code for two main programs

More information

Compilation & linkage. Compilation & linkage. Make. Compilation & linkage. Explicit rules. What makefile contains

Compilation & linkage. Compilation & linkage. Make. Compilation & linkage. Explicit rules. What makefile contains Linkage: g++ read main list o Compilation: g++ -c read main list read read read main main list list list If only one file is modified, do we have to recompile all over again? No. The Makefile uses the

More information

COMS W3101 Programming Language: C++ (Fall 2015) Ramana Isukapalli

COMS W3101 Programming Language: C++ (Fall 2015) Ramana Isukapalli COMS W3101 Programming Language: C++ (Fall 2015) ramana@cs.columbia.edu Lecture-2 Overview of C continued C character arrays Functions Structures Pointers C++ string class C++ Design, difference with C

More information

CSCI 171 Chapter Outlines

CSCI 171 Chapter Outlines Contents CSCI 171 Chapter 1 Overview... 2 CSCI 171 Chapter 2 Programming Components... 3 CSCI 171 Chapter 3 (Sections 1 4) Selection Structures... 5 CSCI 171 Chapter 3 (Sections 5 & 6) Iteration Structures

More information

The make utility. Alark Joshi COMPSCI 253

The make utility. Alark Joshi COMPSCI 253 The make utility Alark Joshi COMPSCI 253 What is make? Make is a utility that is included with Linux/Unix operating systems It is a command generator It is designed to help you compile large projects It

More information

independent compilation and Make

independent compilation and Make independent compilation and Make Geoffrey Brown David S. Wise Chris Haynes Bryce Himebaugh Computer Structures Fall 2013 Independent Compilation As a matter of style, source code files should rarely be

More information

Lecture 10: building large projects, beginning C++, C++ and structs

Lecture 10: building large projects, beginning C++, C++ and structs CIS 330: / / / / (_) / / / / _/_/ / / / / / \/ / /_/ / `/ \/ / / / _/_// / / / / /_ / /_/ / / / / /> < / /_/ / / / / /_/ / / / /_/ / / / / / \ /_/ /_/_/_/ _ \,_/_/ /_/\,_/ \ /_/ \ //_/ /_/ Lecture 10:

More information

COMS W3101 Programming Language: C++ (Fall 2016) Ramana Isukapalli

COMS W3101 Programming Language: C++ (Fall 2016) Ramana Isukapalli COMS W3101 Programming Language: C++ (Fall 2016) ramana@cs.columbia.edu Lecture-2 Overview of C C++ Functions Structures Pointers Design, difference with C Concepts of Object oriented Programming Concept

More information

Programming in C - Part 2

Programming in C - Part 2 Programming in C - Part 2 CPSC 457 Mohammad Reza Zakerinasab May 11, 2016 These slides are forked from slides created by Mike Clark Where to find these slides and related source code? http://goo.gl/k1qixb

More information

The makeutility automatically determines which pieces of a large program need to be recompiled, and issues commands to recompile them.

The makeutility automatically determines which pieces of a large program need to be recompiled, and issues commands to recompile them. What is make? 1 make is a system utility for managing the build process (compilation/linking/etc). There are various versions of make; these notes discuss the GNU makeutility included on Linux systems.

More information

COMS W3101 Programming Language: C++ (Fall 2015) Ramana Isukapalli

COMS W3101 Programming Language: C++ (Fall 2015) Ramana Isukapalli COMS W3101 Programming Language: C++ (Fall 2015) ramana@cs.columbia.edu Lecture-2 Overview of C continued C character arrays Functions Structures Pointers C++ string class C++ Design, difference with C

More information

Outline. COMP 2718: Software Development Tools: gcc and make. C and Java 3/28/16

Outline. COMP 2718: Software Development Tools: gcc and make. C and Java 3/28/16 Outline COMP 2718: Software Development Tools: gcc and make Slides adapted by Andrew Vardy ( Memorial University) Originally created by Marty Stepp, Jessica Miller, and Ruth Anderson (University of Washington)

More information

Lecture 19 Notes Data Structures in C

Lecture 19 Notes Data Structures in C Lecture 19 Notes Data Structures in C 15-122: Principles of Imperative Computation (Fall 2015) Rob Simmons In this lecture, we will begin our transition to C. In many ways, the lecture is therefore about

More information

CS240: Programming in C

CS240: Programming in C CS240: Programming in C Lecture 2: Hello World! Cristina Nita-Rotaru Lecture 2/ Fall 2013 1 Introducing C High-level programming language Developed between 1969 and 1973 by Dennis Ritchie at the Bell Labs

More information