CSSE 332 Standard Library, Storage classes, and Make

Similar documents
Today s class. Finish review of C Process description and control. Informationsteknologi. Tuesday, September 18, 2007

C introduction: part 1

The C standard library

Programming in C in a UNIX environment

Student Number: Computer Science 211b Final Examination. 28 April hours

OBJECTIVE QUESTIONS: Choose the correct alternative:

BİL200 TUTORIAL-EXERCISES Objective:

C for C++ Programmers

CSE 333 Lecture 7 - final C details

Why learn C (after Java)? C for Java programmers. What does this C program do? Simple Example. Goals of this tutorial

C Functions. CS 2060 Week 4. Prof. Jonathan Ventura

CS Basics 15) Compiling a C prog.

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

CSCI 2132 Final Exam Solutions

CSCI 171 Chapter Outlines

CS 326 Operating Systems C Programming. Greg Benson Department of Computer Science University of San Francisco

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

Writing an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and

Functions. Systems Programming Concepts

Exercise 1: Basic Tools

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 4

CS349/SE382 A1 C Programming Tutorial

Main differences with Java

Function Call Stack and Activation Records

Lecture 03 Bits, Bytes and Data Types

Introduction to Supercomputing

Functions. Functions are everywhere in C. Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR


Fundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University

CprE 288 Introduction to Embedded Systems

CSE 2421: Systems I Low-Level Programming and Computer Organization. Functions. Presentation C. Predefined Functions

Introduction to C Language

Compiling and Running a C Program in Unix

Programming in C week 1 meeting Tiina Niklander

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

SWEN-250 Personal SE. Introduction to C

Intermediate Programming, Spring 2017*

CSE2301. Functions. Functions and Compiler Directives

C mini reference. 5 Binary numbers 12

Dr M Kasim A Jalil. Faculty of Mechanical Engineering UTM (source: Deitel Associates & Pearson)

Basic C Programming. Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

mith College Computer Science CSC352 Week #7 Spring 2017 Introduction to C Dominique Thiébaut

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

CSE 333 Midterm Exam July 24, Name UW ID#

The make Utility in Unix SEEM

The make Utility in Unix SEEM

Programming in C First meeting

PRINCIPLES OF OPERATING SYSTEMS

Intermediate Programming, Spring 2017*

ch = argv[i][++j]; /* why does ++j but j++ does not? */

Getting Started. Project 1

Final C Details. CSE 333 Autumn 2018

Memory and C/C++ modules

THE UNIVERSITY OF WESTERN ONTARIO. COMPUTER SCIENCE 211a FINAL EXAMINATION 17 DECEMBER HOURS

advanced data types (2) typedef. today advanced data types (3) enum. mon 23 sep 2002 defining your own types using typedef

CSE 124 Discussion (10/3) C/C++ Basics

Slide Set 3. for ENCM 339 Fall 2017 Section 01. Steve Norman, PhD, PEng

Programming in C First meeting Tiina Niklander

Content. Input Output Devices File access Function of File I/O Redirection Command-line arguments

Computers Programming Course 5. Iulian Năstac

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

today cs3157-fall2002-sklar-lect05 1

Computer Science & Engineering 150A Problem Solving Using Computers

Final Exam 1 /12 2 /12 3 /10 4 /7 5 /4 6 /10 7 /8 8 /9 9 /8 10 /11 11 /8 12 /10 13 /9 14 /13 15 /10 16 /10 17 /12. Faculty of Computer Science

mith College Computer Science CSC231 Bash Labs Week #10, 11, 12 Spring 2017 Introduction to C Dominique Thiébaut

CSE 351. Introduction & Course Tools

CSSE 332 OPERATING SYSTEMS

Basic I/O. COSC Software Tools. Streams. Standard I/O. Standard I/O. Formatted Output

Computer Science & Engineering 150A Problem Solving Using Computers. Chapter 3. Existing Information. Notes. Notes. Notes. Lecture 03 - Functions

2 Compiling a C program

Technical Questions. Q 1) What are the key features in C programming language?

Fundamentals of Programming Session 12

CSE 374 Programming Concepts & Tools

Lecture 3. Review. CS 141 Lecture 3 By Ziad Kobti -Control Structures Examples -Built-in functions. Conditions: Loops: if( ) / else switch

File I/O. Preprocessor Macros

Arrays, Strings, & Pointers

University of Kelaniya Sri Lanka

COMP322 - Introduction to C++

Creating, Compiling and Executing

C: Arrays, and strings. Department of Computer Science College of Engineering Boise State University. September 11, /16

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

Advanced C Programming Topics

M4.1-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE

C Functions. 5.2 Program Modules in C

Functions. Angela Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan.

Approximately a Test II CPSC 206

MIDTERM EXAM. CS 217 October 28, Name: Precept: Honor Code: Score: Problem Score Max

Computing Science (CMPUT) 201

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

File Handling in C. EECS 2031 Fall October 27, 2014

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

Functions in C C Programming and Software Tools. N.C. State Department of Computer Science

Why arrays? To group distinct variables of the same type under a single name.

Page 1. Agenda. Programming Languages. C Compilation Process

make and makefile CS 211

C BOOTCAMP DAY 2. CS3600, Northeastern University. Alan Mislove. Slides adapted from Anandha Gopalan s CS132 course at Univ.

Design and development of embedded systems for the Internet of Things (IoT) Fabio Angeletti Fabrizio Gattuso

Lecture 9 Assertions and Error Handling CS240

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

CS201- Introduction to Programming Latest Solved Mcqs from Midterm Papers May 07,2011. MIDTERM EXAMINATION Spring 2010

Transcription:

CSSE 332 Standard Library, Storage classes, and Make 1

<stdio.h> Provides a simple and efficient buffered I/O interface from man stdio Prototypes standard I/O functions (Mostly) system-independent (e.g. fprintf, fgets, feof) Defines required types (e.g. FILE) Defines required macros Functions are defined in standard library System-dependent implementations Linked automatically 2

Input and Output functions fgets(stdin, ); Similar to scanf( ) Safe from buffer overflow fprintf(stdout, format, ); Buffered output Equivalent to printf( format, ) fprintf(stderr,, ); Un-buffered output Use for error messages. 3

Other useful libraries and <string.h> header files String processing functions -- str*() & mem*() <ctype.h> Functions for testing characters <math.h> Mathematical functions and macros <stdlib.h> Functions for number conversion, storage allocation, and similar tasks 4

Finding the right library In bash: for x in /usr/lib/*.a; do if ar t $x grep pow &> /dev/null; then echo $x; fi; done 2> /dev/null

Storage classes Visibility: parts of source code within which variable can be referenced Lifetime: phases of execution during which variable is allocated Automatic (default for local variables) e.g. auto int i; Visibility: within statement block Lifetime: execution of statement block Register e.g. register counter = 1; Suggestion to compiler to place variable in a register Visibility and lifetime same as auto 6

More storage classes static e.g. static int i; Visibility: statement block Lifetime: program execution Value is retained and space is de-allocated only when program (not function) terminates. Historically related to Java s static fields 7

More storage classes extern e.g. int count; //declared in file 1 Visibility must be entire file (i.e. global) extern int count; //used in files 2,3 Promises compiler that variable will be visible from another compilation unit Provides type Common practice is to collect externs in a header file 8

enum - enumerated data types #include <stdio.h> enum month{ JANUARY, /* like #define JANUARY 0 */ FEBRUARY, /* like #define FEBRUARY 1 */ MARCH /* */ }; //In main: enum month birthmonth; if(birthmonth == JANUARY){ } /* alternatively,. */ enum month{ JANUARY=1, /* like #define JANUARY 1 */ MARCH=3, /* like #define MARCH 3 */ FEBRUARY=2, /* */ }; Note: if you use the #define, the value of JANUARY will not be visible in 9 the debugger. An enumerated data type s value will be.

Program with multiple files #include <stdio.h> #include mypgm.h int gdata=5; int main(){ myproc(); return 0; } main.c Library headers Standard User-defined #include <stdio.h> #include mypgm.h void myproc(){ int mydata = gdata*2;... /* some code */ } mypgm.c void myproc(); extern int gdata; mypgm.h 10

To compile (by hand) gcc main.c mypgm.c o run or gcc -c main.c -o main.o gcc -c mypgm.c -o mypgm.o gcc mypgm.o main.o -o run 11

In-class exercise Copy the makefile tutorial directory to your working environment, e.g. scp -r merkle@addiator.rosehulman.edu:/class/csse/csse332/0708c/code/ maketutorial temp svn export temp maketutorial rm rf temp 12

In-class exercise (cont.) Compile main.c and author.c Link them Make a change to author.c and build the executable again Make a change to author.h and build the executable again 13

To compile (using a makefile) Run make (woohoo!) 14

In-class exercise (cont.) Run make Make a change to author.c and run make again Make a change to author.h and run make again Examine the makefile Read the comments Note the variables Identify and understand the dependency rules (targets, dependencies, actions) Note on whitespace: Targets must be followed by tabs, not spaces Actions must be preceded by tabs, not spaces This makefile is more complicated than it needs to be, but scales well 15

Tips to programming well in C Always initialize your variables before using their values (especially pointers) Don t use pointers after freeing them Don t return pointers to local variables of functions There are no exceptions, so check for errors everywhere An array is also a pointer, but its value is immutable. Compile your programs with a Makefile 16