0% found this document useful (0 votes)
11 views55 pages

01 Intro

Uploaded by

mandriloquai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views55 pages

01 Intro

Uploaded by

mandriloquai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 55

$ cat welcome.

c
#include <stdio.h>
int main(int argc, char *argv[])
{
printf(“Welcome to COS 217\n");
printf("Introduction to Programming Systems\n\n");
printf("%s %d\n", "Spring", 2019);
return 0;
}
$ cat Makefile
CC=gcc217
welcome: welcome.o
$ make
gcc217 -c -o welcome.o welcome.c
gcc217 welcome.o -o welcome
$ ./welcome
Welcome to COS 217
Introduction to Programming Systems

Spring, 2019
Agenda

Course overview Getting started with C


• Introductions • History of C
• Course goals • Building and running C
• Resources programs
• Grading • Characteristics of C
• Policies • C details (if time)
• Schedule

2
Introductions

Lead Instructor
• Prof. Szymon Rusinkiewicz [email protected]

Lead Preceptors
• Robert Dondero, Ph.D. [email protected]
• Xiaoyan Li [email protected]

Graduate Student Preceptors


• James Heppenstall [email protected]
• Seo Young Kyung [email protected]
• Josh Zhang [email protected]

3
Agenda

Course overview Getting started with C


• Introductions • History of C
• Course goals • Building and running C
• Resources programs
• Grading • Characteristics of C
• Policies • C details (if time)
• Schedule

4
Goal 1: Programming in the Large

Learn how to compose


large computer programs

Topics
• Modularity/abstraction, information hiding, resource management,
error handling, testing, debugging, performance improvement,
tool support

5
Goal 2: Under the Hood

Learn what happens Learn “how to be


“under the hood” of a client of an
computer systems operating system”

Downward tours

C Language Application Program

language service
Assembly Language levels Operating System levels
tour tour
Machine Language Hardware

6
Modularity!
Goals: Summary
Help you to become a...

Power Programmer!!!
8
Specific Goal: Learn C

Question: Why C instead of Java?

Answer 1: A primary language for


“under the hood” programming

Answer 2: Knowing a variety of approaches


helps you “program in the large”

9
Specific Goal: Learn Linux
Question: Why use the Linux operating system?

Answer 1: Linux is the industry standard for servers,


embedded devices, education, and research

Answer 2: Linux (with GNU tools) is good for programming


(which helps explain answer 1)

10
Agenda

Course overview Getting started with C


• Introductions • History of C
• Course goals • Building and running C
• Resources programs
• Grading • Characteristics of C
• Policies • C details (if time)
• Schedule

11
Lectures
Lectures
• Describe material at conceptual (high) level
• Slides available via course website

Etiquette
• Use electronic devices only for taking notes or annotating slides
(but consider taking notes by hand – research shows it works better!)
• No SnapFaceNewsBookInstaGoo, please

iClicker
• Register in Blackboard (not with iClicker – they’ll charge you)
• Occasional questions in class, graded on participation
(with a generous allowance for not being able to attend)
12
iClicker Question
Q: Do you have an iClicker with you today?

A. Yes

B. No, but I’ve been practicing my mental electrotelekinesis and


the response is being registered anyway

C. I’m not here, but someone is iClicking for me


(don’t do this – it’s a violation of our course policies!)
Precepts
Precepts
• Describe material at the “practical” (low) level
• Support your work on assignments
• Hard copy handouts distributed during precepts
• Handouts available via course website

Etiquette
• Attend your precept – attendance will be taken
• Must miss your precept? ⇒ inform preceptors & attend another
• Use SCORE to move to another precept
• Trouble ⇒ See Colleen Kenny (CS Bldg 210)
• But Colleen can’t move you into a full precept

Precepts begin today and tomorrow!

14
Website

http://www.cs.princeton.edu/~cos217/

• Home page, schedule page, assignment page, policies page

15
Piazza

Piazza
• http://piazza.com/princeton/spring2019/cos217
• Instructions provided in first precept

Piazza etiquette
• Study provided material before posting question
• Lecture slides, precept handouts, required readings
• Read / search all (recent) Piazza threads before posting question
• Don’t reveal your code!
• See course policies

16
Books
C Programming: A Modern Approach
(Second Edition) (required)
• King
• C programming language and standard libraries

ARM 64-bit Assembly Language (required)


• Pyeatt & Ughetta
• Preprint will be made available through Pequod

The Practice of Programming (recommended)


• Kernighan & Pike
• “Programming in the large”

Computer Systems: A Programmer’s


Perspective (Third Edition) (recommended)
• Bryant & O'Hallaron
• “Under the hood” 17
Manuals

Manuals (for reference only, available online)


• ARMv8 Instruction Set Overview
• ARM Architecture Reference Manual
• Using as, the GNU Assembler

See also
• Linux man command

18
Programming Environment
Server Client

ArmLab Cluster Your Computer

SSH
Linux OS

GNU
tools

Your
Program

armlab01
armlab02 On-campus
or
off-campus 19
Agenda

Course overview Getting started with C


• Introductions • History of C
• Course goals • Building and running C
• Resources programs
• Grading • Characteristics of C
• Policies • C details (if time)
• Schedule

20
Grading

Course Component Percentage of Grade


Assignments * 50
Midterm Exam ** 15 These
percentages are
Final Exam ** 25 approximate

Participation *** 10

* Final assignment counts double; penalties for lateness


** Closed book, closed notes, no electronic devices
*** Did your involvement benefit the course as a whole?
• Lecture/precept attendance and participation counts

21
Programming Assignments
Regular (not-quite-weekly) assignments

0. Introductory survey
1. “De-comment” program
2. String module
3. Symbol table module
4. Assembly language programs
5. Buffer overrun attack
6. Heap manager module
7. Unix shell
*(some individual, some done with a partner from your precept)

Assignments 0 and 1 are available now


Start early!!!
22
Agenda

Course overview Getting started with C


• Introductions • History of C
• Course goals • Building and running C
• Resources programs
• Grading • Characteristics of C
• Policies • C details (if time)
• Schedule

23
Policies
Learning is a collaborative activity!
• Discussions with others that help you understand
concepts from class are encouraged

But programming assignments are graded!


• Everything that gets submitted for a grade
must be exclusively your own work
• Don’t look at code from someone else, the web,
Github, etc. – see the course “Policies” web page
• Don’t reveal your code or design decisions to anyone except
course staff – see the course “Policies” web page

Violations of course policies


• Typical course-level penalty is F for course
• Typical University-level penalty is suspension from University
for 1 academic year
24
Assignment Related Policies
Some highlights:
• You may not reveal any of your assignment solutions (products,
descriptions of products, design decisions) on Piazza.
• Getting help: To help you compose an assignment solution you
may use only authorized sources of information, may consult with
other people only via the course's Piazza account or via interactions
that might legitimately appear on the course's Piazza account, and
must declare your sources in your readme file for the assignment.
• Giving help: You may help other students with assignments only
via the course's Piazza account or interactions that might
legitimately appear on the course's Piazza account, and you
may not share your assignment solutions with anyone, ever
(including after the semester is over), in any form.

Ask the instructor for clarifications


• Permission to deviate from policies must be obtained in writing.
25
Agenda

Course overview Getting started with C


• Introductions • History of C
• Course goals • Building and running C
• Resources programs
• Grading • Characteristics of C
• Policies • C details (if time)
• Schedule

26
Course Schedule

Weeks Lectures Precepts


1-2 C (conceptual) C (pragmatic)
Number Systems Linux/GNU
3-6 Programming in the Large Advanced C
6 Midterm Exam
7 Spring break!
8-13 “Under the Hood” “Under the Hood”
(conceptual) (assignment how-to)
Reading Period
Final Exam

27
Questions?

28
Agenda

Course overview Getting started with C


• Introductions • History of C
• Course goals • Building and running C
• Resources programs
• Grading • Characteristics of C
• Policies • C details (if time)
• Schedule

29
The C Programming Language

Who? Dennis Ritchie


When? ~1972
Where? Bell Labs
Why? Build the Unix OS

30
Java vs. C: History
This is what
we’re using

1960 1970 1972 1978 1989 1999 2011


ANSI C89 ISO C99
BCPL B C K&R C ISO C11
ISO C90 ANSI C99

Algol

Simula C++ Java

LISP Smalltalk

31
C vs. Java: Design Goals

C Design Goals (1972) Java Design Goals (1995)


Build the Unix OS Language of the Internet
Low-level; close to HW and OS High-level; insulated from
hardware and OS
Good for system-level Good for application-level
programming programming
Support structured programming Support object-oriented
programming
Unsafe: don’t get in the Safe: can’t step
programmer’s way “outside the sandbox”
Look like C!

32
Agenda

Course overview Getting started with C


• Introductions • History of C
• Course goals • Building and running C
• Resources programs
• Grading • Characteristics of C
• Policies • C details (if time)
• Schedule

33
Building Java Programs
$ javac MyProg.java Java compiler
(machine lang code)

HW (ArmLab)
OS (Linux)
MyProg.java MyProg.class
javac
(Java code) (bytecode)

34
Running Java Programs
$ java MyProg Java interpreter /
“virtual machine”
(machine lang code)
HW (ArmLab)
OS (Linux)

data java data

MyProg.class
(bytecode)

35
Building C Programs
$ gcc217 myprog.c –o myprog C “Compiler driver”
(machine lang code)

HW (ArmLab)
OS (Linux)
myprog.c myprog
gcc217
(C code) (machine lang code)

36
Running C Programs
$ ./myprog myprog
(machine lang code)

HW (ArmLab)
OS (Linux)

data myprog data

37
Agenda

Course overview Getting started with C


• Introductions • History of C
• Course goals • Building and running C
• Resources programs
• Grading • Characteristics of C
• Policies • C details (if time)
• Schedule

38
Java vs. C: Portability

Program Code Type Portable?


MyProg.java Java source code Yes
myprog.c C source code Mostly

MyProg.class Bytecode Yes


myprog Machine lang code No

Conclusion: Java programs are more portable

(In particular, this semester we’re moving from the


x86_64-based “courselab” to the ARM64-based “armlab”,
and all of the programs must be recompiled!)
39
Java vs. C: Safety & Efficiency
Java
• Automatic array-bounds checking,
• NULL pointer checking,
• Automatic memory management (garbage collection)
• Other safety features

C
• Manual bounds checking
• NULL pointer checking,
• Manual memory management

Conclusion 1: Java is often safer than C


Conclusion 2: Java is often slower than C
40
Java vs. C: Characteristics

Java C
Portability + -
Efficiency - +
Safety + -

41
iClicker Question
Q: Which corresponds to the C programming language?

A.

B.

C.
Agenda

Course overview Getting started with C


• Introductions • History of C
• Course goals • Building and running C
• Resources programs
• Grading • Characteristics of C
• Policies • C details (if time)
• Schedule

43
Java vs. C: Details

Remaining slides provide some details

Use for future reference

Slides covered now, as time allows…

44
Java vs. C: Details

Java C
Hello.java: hello.c:
public class Hello #include <stdio.h>
Overall { public static void main
(String[] args) int main(void)
Program
{ System.out.println( { printf("hello, world\n");
Structure return 0;
"hello, world");
} }
}

Building $ javac Hello.java $ gcc217 hello.c –o hello

$ java Hello $ ./hello


Running hello, world hello, world
$ $

45
Java vs. C: Details
Java C
Character type char // 16-bit Unicode char /* 8 bits */
byte // 8 bits (unsigned, signed) char
short // 16 bits (unsigned, signed) short
Integral types
int // 32 bits (unsigned, signed) int
long // 64 bits (unsigned, signed) long
float
Floating point float // 32 bits
double
types double // 64 bits
long double
/* no equivalent */
Logical type boolean
/* use 0 and non-0 */
Generic pointer
Object void*
type
#define MAX 1000
Constants final int MAX = 1000; const int MAX = 1000;
enum {MAX = 1000};

46
Java vs. C: Details
Java C
int [] a = new int [10]; int a[10];
Arrays float [][] b = float b[5][20];
new float [5][20];
Array bound
// run-time check /* no run-time check */
checking
// Object reference is an
Pointer type int *p;
// implicit pointer
class Mine struct Mine
{ int x; { int x;
Record type
float y; float y;
} };

47
Java vs. C: Details
Java C
String s1 = "Hello"; char *s1 = "Hello";
Strings String s2 = new char s2[6];
String("hello"); strcpy(s2, "hello");
String s1 + s2 #include <string.h>
concatenation s1 += s2 strcat(s1, s2);
Logical ops * &&, ||, ! &&, ||, !
Relational ops * =, !=, <, >, <=, >= =, !=, <, >, <=, >=

Arithmetic ops * +, -, *, /, %, unary - +, -, *, /, %, unary -

Bitwise ops <<, >>, >>>, &, ^, |, ~ <<, >>, &, ^, |, ~

=, +=, -=, *=, /=, %=, =, +=, -=, *=, /=, %=,
Assignment ops
<<=, >>=, >>>=, &=, ^=, |= <<=, >>=, &=, ^=, |=

* Essentially the same in the two languages


48
Java vs. C: Details
Java C
if (i < 0) if (i < 0)
statement1; statement1;
if stmt *
else else
statement2; statement2;
switch (i) switch (i)
{ case 1: { case 1:
... ...
break; break;
case 2: case 2:
switch stmt *
... ...
break; break;
default: default:
... ...
} }

goto stmt // no equivalent goto someLabel;

* Essentially the same in the two languages


49
Java vs. C: Details
Java C
int i;
for (int i=0; i<10; i++)
for stmt for (i=0; i<10; i++)
statement;
statement;
while (i < 0) while (i < 0)
while stmt *
statement; statement;
do do
do-while stmt * statement; statement;
while (i < 0) while (i < 0);
continue stmt * continue; continue;
labeled continue
continue someLabel; /* no equivalent */
stmt
break stmt * break; break;
labeled break
break someLabel; /* no equivalent */
stmt

* Essentially the same in the two languages


50
Java vs. C: Details
Java C
return 5; return 5;
return stmt *
return; return;
{ {
Compound stmt statement1; statement1;
(alias block) * statement2; statement2;
} }

Exceptions throw, try-catch-finally /* no equivalent */

/* comment */ /* comment */
Comments
// another kind
f(x, y, z);
Method / function
someObject.f(x, y, z); f(x, y, z);
call
SomeClass.f(x, y, z);

* Essentially the same in the two languages


51
Example C Program
#include <stdio.h>
#include <stdlib.h>

int main(void)
{ const double KMETERS_PER_MILE = 1.609;
int miles;
double kMeters;

printf("miles: ");
if (scanf("%d", &miles) != 1)
{ fprintf(stderr, "Error: Expected a number.\n");
exit(EXIT_FAILURE);
}

kMeters = (double)miles * KMETERS_PER_MILE;


printf("%d miles is %f kilometers.\n",
miles, kMeters);
return 0;
}
52
Summary

Course overview
• Introductions
• Course goals
• Goal 1: Learn “programming in the large”
• Goal 2: Look “under the hood”and learn low-level programming
• Use of C and Linux supports both goals
• Resources
• Lectures, precepts, programming environment, Piazza, textbooks
• Course website: access via http://www.cs.princeton.edu
• Grading
• Policies
• Schedule

53
Summary

Getting started with C


• History of C
• Building and running C programs
• Characteristics of C
• Details of C
• Java and C are similar
• Knowing Java gives you a head start at learning C

54
Getting Started

Check out course website soon


• Study “Policies” page
• First assignment is available

Establish a reasonable computing environment soon


• Instructions given in first precept

55

You might also like