SlideShare a Scribd company logo
1 of 38
Download to read offline
1
COS 217: Introduction to
Programming Systems
!
Jennifer Rexford
!
2
Goals for Todayʼs Class!
• Course overview!
• Introductions!
• Course goals!
• Resources!
• Grading!
• Policies!
• Getting started with C!
• C programming language overview!
3
Introductions!
• Lectures!
• Jennifer Rexford (Professor)!
• jrex@cs.princeton.edu !
• Preceptors!
• Christopher Moretti (Lead Preceptor)!
• cmoretti@cs.princeton.edu!
• Sibren Isaacman!
• isaacman@princeton.edu!
4
Course Goal 1: “Programming in the Large”!
• Help you learn how to write large
computer programs!
• Specifically:!
• Write modular code!
• Write portable code!
• Test and debug your code!
• Improve your codeʼs performance (and when to do so)!
• Use tools to support those activities!
5
Course Goal 2: “Under the Hood”!
• Help you learn what happens
“under the hood” of computer systems!
• Two downward tours!
• Goal 2 supports Goal 1!
• Reveals many examples of effective abstractions!
C Language!
Assembly Language!
Machine Language!
Application Program!
Operating System!
Hardware!
language!
levels!
tour!
service!
levels!
tour!
6
Course Goals: Why C Instead of Java?!
• A: C supports Goal 1 better!
• C is a lower-level language!
• C provides more opportunities to create abstractions!
• C has some flaws!
• Cʼs flaws motivate discussions of software
engineering principles!
• A: C supports Goal 2 better!
• C facilitates language levels tour!
• C is closely related to assembly language!
• C facilitates service levels tour!
• Linux is written in C!
7
Course Goals: Why Linux?!
• A: Linux is good for education and research!
• Linux is open-source and well-specified!
• A: Linux is good for programming!
• Linux is a variant of Unix!
• Unix has GNU, a rich open-source programming
environment!
8
Course Goals: Summary!
• Help you to become a...!
Power Programmer!!!!
9
Resources: Lectures and Precepts!
• Lectures!
• Describe concepts at a high level!
• Slides available online at course Web site!
• Precepts!
• Support lectures by describing concepts at a lower level!
• Support your work on assignments!
• Note: Precepts begin on Monday (i.e., today)!
• P01: MW 1:30-2:20pm, in CS 102!
• P02: TTh 1:30-2:20pm, in CS 102!
• P03: TTh 7:30-8:20pm, in CS 102!
10
Resources: Website and Piazzza!
• Website!
• Access from http://www.cs.princeton.edu!
• Academics → Course Schedule → COS 217!
• Discussion forum!
• Piazzza: http://www.piazzza.com!
• “Join or create your class now”!
• School: Princeton University!
• Class: COS 217!
• Fill in your Princeton e-mail address!
• Click “get started” link in your email to activate!
• Please use your real name when signing up!
11
Resources: Books!
• Required book!
• C Programming: A Modern Approach (Second Edition), King, 2008.!
• Covers the C programming language and standard libraries!
• Highly recommended books!
• The Practice of Programming, Kernighan and Pike, 1999. !
• Covers “programming in the large” (required for COS 333)!
• Computer Systems: A Programmer's Perspective (Second Edition),
Bryant and O'Hallaron, 2010.!
• Covers “under the hood,” key sections are on e-reserve!
• First edition is sufficient!
• Programming with GNU Software, Loukides and Oram, 1997.!
• Covers tools!
• All books are on reserve in Engineering Library!
12
Resources: Manuals!
• Manuals (for reference only, available online)!
• IA32 Intel Architecture Software Developer's Manual, Volumes 1-3!
• Tool Interface Standard & Executable and Linking Format!
• Using as, the GNU Assembler !
• See also!
• Linux man command!
• man is short for “manual”!
• For more help, type man man!
13
Resources: Programming Environment!
Friend Center 016!
or 017 Computer!
hats.princeton.edu!
SSH!
Lab TAs!
Linux!
GNU!
• Option 1!
Your!
Pgm!
fedora!
fez!
14
Resources: Programming Environment!
Your PC/Mac/Linux!
Computer!
SSH!
• Option 2!
hats.princeton.edu!
Linux!
GNU!
Your!
Pgm!
fedora!
fez!
15
Resources: Programming Environment!
• Other options!
• Use your own PC/Mac/Linux computer; run GNU tools
locally; run your programs locally!
• Use your own PC/Mac/Linux computer; run a non-GNU
development environment locally; run programs locally!
• Notes!
• Other options cannot be used for some assignments
(esp. timing studies)!
• Instructors cannot promise support of other options!
• Strong recommendation: Use Option 1 or 2 for all
assignments!
• First precept provides setup instructions!
16
Grading!
• Seven programming assignments (50%)!
• Working code!
• Clean, readable, maintainable code!
• On time (penalties for late submission)!
• Final assignment counts double (12.5%)!
• Exams (40%)!
• Midterm (15%)!
• Final (25%)!
• Class participation (10%)!
• Lecture and precept attendance is mandatory!
17
Programming Assignments!
• Programming assignments!
1. A “de-comment” program!
2. A string module!
3. A symbol table module !
4. IA-32 assembly language programs!
5. A buffer overrun attack!
6. A heap manager module!
7. A Unix shell !
• See course “Schedule” web page for due dates/times!
• Advice: Start early to allow time for debugging (especially in
the background while you are doing other things!)…!
18
Why Debugging is Necessary…!
19
Policies!
Study the course “Policies” web page!!!!
• Especially the assignment collaboration policies!
• Violation involves trial by Committee on Discipline!
• Typical penalty is suspension from University for 1 academic year!
• Some highlights:!
• Donʼt view anyone elseʼs work during, before, or after the
assignment time period!
• Donʼt allow anyone to view your work during, before, or after the
assignment time period!
• In your assignment “readme” file, acknowledge all resources used!
• Ask your preceptor for clarifications if necessary!
20
Course Schedule!
• Very generally…!
Weeks! Lectures! Precepts!
1-2! Intro to C (conceptual)! Intro to Linux/GNU
Intro to C (mechanical)!
3-6! “Pgmming in the Large”! Advanced C!
6! Midterm Exam
!
7! Recess
!
8-13! “Under the Hood”! Assembly Language
Pgmming Assignments!
Reading Period
!
Final Exam
!
• See course “Schedule” web page for details!
21
Any questions before we start?
!
22
C vs. Java: History!
BCPL! B! C! K&R C!
ANSI C89!
ISO C90!
ISO/ANSI C99!
1960! 1970! 1972! 1978! 1989! 1999!
LISP! Smalltalk! C++! Java!
Not yet popular;!
our compiler !
supports only!
partially!
We will use!
23
C vs. Java: Design Goals!
• Java design goals!
• Support object-oriented programming!
• Allow same program runs on multiple operating systems !
• Support using computer networks !
• Execute code from remote sources securely!
• Adopt the good parts of other languages!
• Implications for Java!
• Good for application-level programming!
• High-level (insulates from assembly language, hardware)!
• Portability over efficiency!
• Security over efficiency!
• Security over flexibility!
24
C vs. Java: Design Goals!
• C design goals!
• Support structured programming!
• Support development of the Unix OS and Unix tools!
• As Unix became popular, so did C!
• Implications for C!
• Good for system-level programming!
• Low-level!
• Efficiency over portability!
• Efficiency over security!
• Flexibility over security!
25
C vs. Java: Design Goals!
• Differences in design goals explain many differences
between the languages!
• Cʼs design goal explains many of its eccentricities!
• Weʼll see examples throughout the course!
26
C vs. Java: Overview!
• Dennis Ritchie on the nature of C:!
• “C has always been a language that never attempts to tie a
programmer down.”!
• “C has always appealed to systems programmers who like the terse,
concise manner in which powerful expressions can be coded.” !
• “C allowed programmers to (while sacrificing portability) have direct
access to many machine-level features that would otherwise require
the use of assembly language.”!
• “C is quirky, flawed, and an enormous success. While accidents of
history surely helped, it evidently satisfied a need for a system
implementation language efficient enough to displace assembly
language, yet sufficiently abstract and fluent to describe algorithms
and interactions in a wide variety of environments.”!
27
C vs. Java: Overview (cont.)!
• Bad things you can do in C that you canʼt do in Java!
• Shoot yourself in the foot (safety)!
• Shoot others in the foot (security)!
• Ignore wounds (error handling)!
• Dangerous things you must do in C that you donʼt in Java!
• Explicitly manage memory via malloc() and free()
• Good things you can do in C, but (more or less) must do in
Java!
• Program using the object-oriented style!
• Good things you canʼt do in C but can do in Java!
• Write completely portable code!
28
C vs. Java: Details!
• Remaining slides provide some details!
• Suggestion: Use for future reference!
• Slides covered briefly now, as time allows…!
29
C vs. Java: Details (cont.)!
Java
! C
!
Overall
Program
Structure!
Hello.java:
public class Hello {
public static void
main(String[] args) {
System.out.println(
"Hello, world");
}
}
hello.c:
#include <stdio.h>
int main(void) {
printf("Hello, worldn");
return 0;
}
Building!
% javac Hello.java
% ls
Hello.class
Hello.java
%
% gcc217 hello.c
% ls
a.out
hello.c
%
Running!
% java Hello
Hello, world
%
% a.out
Hello, world
%
30
C vs. Java: Details (cont.)!
Java
! C
!
Character type! char // 16-bit unicode char /* 8 bits */
Integral types!
byte // 8 bits
short // 16 bits
int // 32 bits
long // 64 bits
(unsigned) char
(unsigned) short
(unsigned) int
(unsigned) long
Floating point
types!
float // 32 bits
double // 64 bits
float
double
long double
Logical type! boolean
/* no equivalent */
/* use integral type */
Generic
pointer type!
// no equivalent void*
Constants! final int MAX = 1000;
#define MAX 1000
const int MAX = 1000;
enum {MAX = 1000};
31
C vs. Java: Details (cont.)!
Java
! C
!
Arrays!
int [] a = new int [10];
float [][] b =
new float [5][20];
int a[10];
float b[5][20];
Array bound
checking!
// run-time check /* no run-time check */
Pointer type!
// Object reference is an
// implicit pointer
int *p;
Record type!
class Mine {
int x;
float y;
}
struct Mine {
int x;
float y;
}
32
C vs. Java: Details (cont.)!
Java
! C
!
Strings!
String s1 = "Hello";
String s2 = new
String("hello");
char *s1 = "Hello";
char s2[6];
strcpy(s2, "hello");
String
concatenation!
s1 + s2
s1 += s2
#include <string.h>
strcat(s1, s2);
Logical ops! &&, ||, ! &&, ||, !
Relational ops! =, !=, >, <, >=, <= =, !=, >, <, >=, <=
Arithmetic
ops!
+, -, *, /, %, unary - +, -, *, /, %, unary -
Bitwise ops! >>, <<, >>>, &, |, ^ >>, <<, &, |, ^
Assignment
ops!
=, *=, /=, +=, -=, <<=,
>>=, >>>=, =, ^=, |=, %=
=, *=, /=, +=, -=, <<=,
>>=, =, ^=, |=, %=
33
C vs. Java: Details (cont.)!
Java
! C
!
if stmt!
if (i < 0)
statement1;
else
statement2;
if (i < 0)
statement1;
else
statement2;
switch stmt!
switch (i) {
case 1:
...
break;
case 2:
...
break;
default:
...
}
switch (i) {
case 1:
...
break;
case 2:
...
break;
default:
...
}
goto stmt! // no equivalent goto SomeLabel;
34
C vs. Java: Details (cont.)!
Java
! C
!
for stmt!
for (int i=0; i<10; i++)
statement;
int i;
for (i=0; i<10; i++)
statement;
while stmt!
while (i < 0)
statement;
while (i < 0)
statement;
do-while stmt!
do {
statement;
…
} while (i < 0)
do {
statement;
…
} while (i < 0);
continue stmt! continue; continue;
labeled
continue stmt!
continue SomeLabel; /* no equivalent */
break stmt! break; break;
labeled break
stmt!
break SomeLabel; /* no equivalent */
35
C vs. Java: Details (cont.)!
Java
! C
!
return stmt!
return 5;
return;
return 5;
return;
Compound stmt
(alias block)!
{
statement1;
statement2;
}
{
statement1;
statement2;
}
Exceptions! throw, try-catch-finally /* no equivalent */
Comments!
/* comment */
// another kind
/* comment */
Method /
function call!
f(x, y, z);
someObject.f(x, y, z);
SomeClass.f(x, y, z);
f(x, y, z);
36
Example C Program!
#include <stdio.h>
#include <stdlib.h>
const double KMETERS_PER_MILE = 1.609;
int main(void) {
int miles;
double kmeters;
printf("miles: ");
if (scanf("%d", &miles) != 1) {
fprintf(stderr, "Error: Expect a number.n");
exit(EXIT_FAILURE);
}
kmeters = miles * KMETERS_PER_MILE;
printf("%d miles is %f kilometers.n",
miles, kmeters);
return 0;
}
37
Conclusions!
• Getting started with C!
• C was designed for system programming!
• Different design goals from of Java!
• Explains many of Cʼs eccentricities!
• Knowing Java gives you a head start at learning C!
• C is not object-oriented, but many aspects are similar!
• Getting started in the course!
• Check out course Web site soon!
• Study “Policies” page!
• First assignment!
• Establish a reasonable computing environment soon!
• Instructions given in first precept!
38
Getting Started!
• Check out course Web site soon!
• Study “Policies” page!
• First assignment is available!
• Establish a reasonable computing environment soon!
• Instructions given in first precept!

More Related Content

Similar to 01Introsystem programming to study computer .pdf

Advance C# Programming Part 1.pdf
Advance C# Programming Part 1.pdfAdvance C# Programming Part 1.pdf
Advance C# Programming Part 1.pdfpercivalfernandez2
 
Programing fundamentals with C++
Programing fundamentals with C++Programing fundamentals with C++
Programing fundamentals with C++farooq2016
 
Desert Code Camp 2014: C#, the best programming language
Desert Code Camp 2014: C#, the best programming languageDesert Code Camp 2014: C#, the best programming language
Desert Code Camp 2014: C#, the best programming languageJames Montemagno
 
Xcode, Basics and Beyond
Xcode, Basics and BeyondXcode, Basics and Beyond
Xcode, Basics and Beyondrsebbe
 
Letter to a Junior Developer: The Engineering Side of Programming
Letter to a Junior Developer: The Engineering Side of ProgrammingLetter to a Junior Developer: The Engineering Side of Programming
Letter to a Junior Developer: The Engineering Side of ProgrammingLazar Kovacevic
 
Introduction to course
Introduction to courseIntroduction to course
Introduction to coursenikit meshram
 
Programming Languages #devcon2013
Programming Languages #devcon2013Programming Languages #devcon2013
Programming Languages #devcon2013Iván Montes
 
Developer Job in Practice
Developer Job in PracticeDeveloper Job in Practice
Developer Job in Practiceintive
 
Introduct To C Language Programming
Introduct To C Language ProgrammingIntroduct To C Language Programming
Introduct To C Language Programmingyarkhosh
 
Open Source Design at Ignite lightning talk
Open Source Design at Ignite lightning talkOpen Source Design at Ignite lightning talk
Open Source Design at Ignite lightning talkMushon Zer-Aviv
 
DownTheRabbitHole.js – How to Stay Sane in an Insane Ecosystem
DownTheRabbitHole.js – How to Stay Sane in an Insane EcosystemDownTheRabbitHole.js – How to Stay Sane in an Insane Ecosystem
DownTheRabbitHole.js – How to Stay Sane in an Insane EcosystemFITC
 
Introduction to programming - class 1
Introduction to programming - class 1Introduction to programming - class 1
Introduction to programming - class 1Paul Brebner
 
Creating a textual domain specific language
Creating a textual domain specific languageCreating a textual domain specific language
Creating a textual domain specific languageVicente García Díaz
 
Introduction to computers
Introduction to computersIntroduction to computers
Introduction to computersLearn By Watch
 

Similar to 01Introsystem programming to study computer .pdf (20)

Advance C# Programming Part 1.pdf
Advance C# Programming Part 1.pdfAdvance C# Programming Part 1.pdf
Advance C# Programming Part 1.pdf
 
Programing fundamentals with C++
Programing fundamentals with C++Programing fundamentals with C++
Programing fundamentals with C++
 
Desert Code Camp 2014: C#, the best programming language
Desert Code Camp 2014: C#, the best programming languageDesert Code Camp 2014: C#, the best programming language
Desert Code Camp 2014: C#, the best programming language
 
Xcode, Basics and Beyond
Xcode, Basics and BeyondXcode, Basics and Beyond
Xcode, Basics and Beyond
 
Letter to a Junior Developer: The Engineering Side of Programming
Letter to a Junior Developer: The Engineering Side of ProgrammingLetter to a Junior Developer: The Engineering Side of Programming
Letter to a Junior Developer: The Engineering Side of Programming
 
Lecture1.ppt
Lecture1.pptLecture1.ppt
Lecture1.ppt
 
Introduction to course
Introduction to courseIntroduction to course
Introduction to course
 
Programming Languages #devcon2013
Programming Languages #devcon2013Programming Languages #devcon2013
Programming Languages #devcon2013
 
Introduction
IntroductionIntroduction
Introduction
 
Developer Job in Practice
Developer Job in PracticeDeveloper Job in Practice
Developer Job in Practice
 
Introduction to programming languages
Introduction to programming languagesIntroduction to programming languages
Introduction to programming languages
 
Introduct To C Language Programming
Introduct To C Language ProgrammingIntroduct To C Language Programming
Introduct To C Language Programming
 
Plc part 1
Plc part 1Plc part 1
Plc part 1
 
C_Programming_Notes_ICE
C_Programming_Notes_ICEC_Programming_Notes_ICE
C_Programming_Notes_ICE
 
Open Source Design at Ignite lightning talk
Open Source Design at Ignite lightning talkOpen Source Design at Ignite lightning talk
Open Source Design at Ignite lightning talk
 
DownTheRabbitHole.js – How to Stay Sane in an Insane Ecosystem
DownTheRabbitHole.js – How to Stay Sane in an Insane EcosystemDownTheRabbitHole.js – How to Stay Sane in an Insane Ecosystem
DownTheRabbitHole.js – How to Stay Sane in an Insane Ecosystem
 
Java basics
Java basicsJava basics
Java basics
 
Introduction to programming - class 1
Introduction to programming - class 1Introduction to programming - class 1
Introduction to programming - class 1
 
Creating a textual domain specific language
Creating a textual domain specific languageCreating a textual domain specific language
Creating a textual domain specific language
 
Introduction to computers
Introduction to computersIntroduction to computers
Introduction to computers
 

Recently uploaded

Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxAmita Gupta
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxcallscotland1987
 

Recently uploaded (20)

Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 

01Introsystem programming to study computer .pdf

  • 1. 1 COS 217: Introduction to Programming Systems ! Jennifer Rexford !
  • 2. 2 Goals for Todayʼs Class! • Course overview! • Introductions! • Course goals! • Resources! • Grading! • Policies! • Getting started with C! • C programming language overview!
  • 3. 3 Introductions! • Lectures! • Jennifer Rexford (Professor)! • jrex@cs.princeton.edu ! • Preceptors! • Christopher Moretti (Lead Preceptor)! • cmoretti@cs.princeton.edu! • Sibren Isaacman! • isaacman@princeton.edu!
  • 4. 4 Course Goal 1: “Programming in the Large”! • Help you learn how to write large computer programs! • Specifically:! • Write modular code! • Write portable code! • Test and debug your code! • Improve your codeʼs performance (and when to do so)! • Use tools to support those activities!
  • 5. 5 Course Goal 2: “Under the Hood”! • Help you learn what happens “under the hood” of computer systems! • Two downward tours! • Goal 2 supports Goal 1! • Reveals many examples of effective abstractions! C Language! Assembly Language! Machine Language! Application Program! Operating System! Hardware! language! levels! tour! service! levels! tour!
  • 6. 6 Course Goals: Why C Instead of Java?! • A: C supports Goal 1 better! • C is a lower-level language! • C provides more opportunities to create abstractions! • C has some flaws! • Cʼs flaws motivate discussions of software engineering principles! • A: C supports Goal 2 better! • C facilitates language levels tour! • C is closely related to assembly language! • C facilitates service levels tour! • Linux is written in C!
  • 7. 7 Course Goals: Why Linux?! • A: Linux is good for education and research! • Linux is open-source and well-specified! • A: Linux is good for programming! • Linux is a variant of Unix! • Unix has GNU, a rich open-source programming environment!
  • 8. 8 Course Goals: Summary! • Help you to become a...! Power Programmer!!!!
  • 9. 9 Resources: Lectures and Precepts! • Lectures! • Describe concepts at a high level! • Slides available online at course Web site! • Precepts! • Support lectures by describing concepts at a lower level! • Support your work on assignments! • Note: Precepts begin on Monday (i.e., today)! • P01: MW 1:30-2:20pm, in CS 102! • P02: TTh 1:30-2:20pm, in CS 102! • P03: TTh 7:30-8:20pm, in CS 102!
  • 10. 10 Resources: Website and Piazzza! • Website! • Access from http://www.cs.princeton.edu! • Academics → Course Schedule → COS 217! • Discussion forum! • Piazzza: http://www.piazzza.com! • “Join or create your class now”! • School: Princeton University! • Class: COS 217! • Fill in your Princeton e-mail address! • Click “get started” link in your email to activate! • Please use your real name when signing up!
  • 11. 11 Resources: Books! • Required book! • C Programming: A Modern Approach (Second Edition), King, 2008.! • Covers the C programming language and standard libraries! • Highly recommended books! • The Practice of Programming, Kernighan and Pike, 1999. ! • Covers “programming in the large” (required for COS 333)! • Computer Systems: A Programmer's Perspective (Second Edition), Bryant and O'Hallaron, 2010.! • Covers “under the hood,” key sections are on e-reserve! • First edition is sufficient! • Programming with GNU Software, Loukides and Oram, 1997.! • Covers tools! • All books are on reserve in Engineering Library!
  • 12. 12 Resources: Manuals! • Manuals (for reference only, available online)! • IA32 Intel Architecture Software Developer's Manual, Volumes 1-3! • Tool Interface Standard & Executable and Linking Format! • Using as, the GNU Assembler ! • See also! • Linux man command! • man is short for “manual”! • For more help, type man man!
  • 13. 13 Resources: Programming Environment! Friend Center 016! or 017 Computer! hats.princeton.edu! SSH! Lab TAs! Linux! GNU! • Option 1! Your! Pgm! fedora! fez!
  • 14. 14 Resources: Programming Environment! Your PC/Mac/Linux! Computer! SSH! • Option 2! hats.princeton.edu! Linux! GNU! Your! Pgm! fedora! fez!
  • 15. 15 Resources: Programming Environment! • Other options! • Use your own PC/Mac/Linux computer; run GNU tools locally; run your programs locally! • Use your own PC/Mac/Linux computer; run a non-GNU development environment locally; run programs locally! • Notes! • Other options cannot be used for some assignments (esp. timing studies)! • Instructors cannot promise support of other options! • Strong recommendation: Use Option 1 or 2 for all assignments! • First precept provides setup instructions!
  • 16. 16 Grading! • Seven programming assignments (50%)! • Working code! • Clean, readable, maintainable code! • On time (penalties for late submission)! • Final assignment counts double (12.5%)! • Exams (40%)! • Midterm (15%)! • Final (25%)! • Class participation (10%)! • Lecture and precept attendance is mandatory!
  • 17. 17 Programming Assignments! • Programming assignments! 1. A “de-comment” program! 2. A string module! 3. A symbol table module ! 4. IA-32 assembly language programs! 5. A buffer overrun attack! 6. A heap manager module! 7. A Unix shell ! • See course “Schedule” web page for due dates/times! • Advice: Start early to allow time for debugging (especially in the background while you are doing other things!)…!
  • 18. 18 Why Debugging is Necessary…!
  • 19. 19 Policies! Study the course “Policies” web page!!!! • Especially the assignment collaboration policies! • Violation involves trial by Committee on Discipline! • Typical penalty is suspension from University for 1 academic year! • Some highlights:! • Donʼt view anyone elseʼs work during, before, or after the assignment time period! • Donʼt allow anyone to view your work during, before, or after the assignment time period! • In your assignment “readme” file, acknowledge all resources used! • Ask your preceptor for clarifications if necessary!
  • 20. 20 Course Schedule! • Very generally…! Weeks! Lectures! Precepts! 1-2! Intro to C (conceptual)! Intro to Linux/GNU Intro to C (mechanical)! 3-6! “Pgmming in the Large”! Advanced C! 6! Midterm Exam ! 7! Recess ! 8-13! “Under the Hood”! Assembly Language Pgmming Assignments! Reading Period ! Final Exam ! • See course “Schedule” web page for details!
  • 21. 21 Any questions before we start? !
  • 22. 22 C vs. Java: History! BCPL! B! C! K&R C! ANSI C89! ISO C90! ISO/ANSI C99! 1960! 1970! 1972! 1978! 1989! 1999! LISP! Smalltalk! C++! Java! Not yet popular;! our compiler ! supports only! partially! We will use!
  • 23. 23 C vs. Java: Design Goals! • Java design goals! • Support object-oriented programming! • Allow same program runs on multiple operating systems ! • Support using computer networks ! • Execute code from remote sources securely! • Adopt the good parts of other languages! • Implications for Java! • Good for application-level programming! • High-level (insulates from assembly language, hardware)! • Portability over efficiency! • Security over efficiency! • Security over flexibility!
  • 24. 24 C vs. Java: Design Goals! • C design goals! • Support structured programming! • Support development of the Unix OS and Unix tools! • As Unix became popular, so did C! • Implications for C! • Good for system-level programming! • Low-level! • Efficiency over portability! • Efficiency over security! • Flexibility over security!
  • 25. 25 C vs. Java: Design Goals! • Differences in design goals explain many differences between the languages! • Cʼs design goal explains many of its eccentricities! • Weʼll see examples throughout the course!
  • 26. 26 C vs. Java: Overview! • Dennis Ritchie on the nature of C:! • “C has always been a language that never attempts to tie a programmer down.”! • “C has always appealed to systems programmers who like the terse, concise manner in which powerful expressions can be coded.” ! • “C allowed programmers to (while sacrificing portability) have direct access to many machine-level features that would otherwise require the use of assembly language.”! • “C is quirky, flawed, and an enormous success. While accidents of history surely helped, it evidently satisfied a need for a system implementation language efficient enough to displace assembly language, yet sufficiently abstract and fluent to describe algorithms and interactions in a wide variety of environments.”!
  • 27. 27 C vs. Java: Overview (cont.)! • Bad things you can do in C that you canʼt do in Java! • Shoot yourself in the foot (safety)! • Shoot others in the foot (security)! • Ignore wounds (error handling)! • Dangerous things you must do in C that you donʼt in Java! • Explicitly manage memory via malloc() and free() • Good things you can do in C, but (more or less) must do in Java! • Program using the object-oriented style! • Good things you canʼt do in C but can do in Java! • Write completely portable code!
  • 28. 28 C vs. Java: Details! • Remaining slides provide some details! • Suggestion: Use for future reference! • Slides covered briefly now, as time allows…!
  • 29. 29 C vs. Java: Details (cont.)! Java ! C ! Overall Program Structure! Hello.java: public class Hello { public static void main(String[] args) { System.out.println( "Hello, world"); } } hello.c: #include <stdio.h> int main(void) { printf("Hello, worldn"); return 0; } Building! % javac Hello.java % ls Hello.class Hello.java % % gcc217 hello.c % ls a.out hello.c % Running! % java Hello Hello, world % % a.out Hello, world %
  • 30. 30 C vs. Java: Details (cont.)! Java ! C ! Character type! char // 16-bit unicode char /* 8 bits */ Integral types! byte // 8 bits short // 16 bits int // 32 bits long // 64 bits (unsigned) char (unsigned) short (unsigned) int (unsigned) long Floating point types! float // 32 bits double // 64 bits float double long double Logical type! boolean /* no equivalent */ /* use integral type */ Generic pointer type! // no equivalent void* Constants! final int MAX = 1000; #define MAX 1000 const int MAX = 1000; enum {MAX = 1000};
  • 31. 31 C vs. Java: Details (cont.)! Java ! C ! Arrays! int [] a = new int [10]; float [][] b = new float [5][20]; int a[10]; float b[5][20]; Array bound checking! // run-time check /* no run-time check */ Pointer type! // Object reference is an // implicit pointer int *p; Record type! class Mine { int x; float y; } struct Mine { int x; float y; }
  • 32. 32 C vs. Java: Details (cont.)! Java ! C ! Strings! String s1 = "Hello"; String s2 = new String("hello"); char *s1 = "Hello"; char s2[6]; strcpy(s2, "hello"); String concatenation! s1 + s2 s1 += s2 #include <string.h> strcat(s1, s2); Logical ops! &&, ||, ! &&, ||, ! Relational ops! =, !=, >, <, >=, <= =, !=, >, <, >=, <= Arithmetic ops! +, -, *, /, %, unary - +, -, *, /, %, unary - Bitwise ops! >>, <<, >>>, &, |, ^ >>, <<, &, |, ^ Assignment ops! =, *=, /=, +=, -=, <<=, >>=, >>>=, =, ^=, |=, %= =, *=, /=, +=, -=, <<=, >>=, =, ^=, |=, %=
  • 33. 33 C vs. Java: Details (cont.)! Java ! C ! if stmt! if (i < 0) statement1; else statement2; if (i < 0) statement1; else statement2; switch stmt! switch (i) { case 1: ... break; case 2: ... break; default: ... } switch (i) { case 1: ... break; case 2: ... break; default: ... } goto stmt! // no equivalent goto SomeLabel;
  • 34. 34 C vs. Java: Details (cont.)! Java ! C ! for stmt! for (int i=0; i<10; i++) statement; int i; for (i=0; i<10; i++) statement; while stmt! while (i < 0) statement; while (i < 0) statement; do-while stmt! do { statement; … } while (i < 0) do { statement; … } while (i < 0); continue stmt! continue; continue; labeled continue stmt! continue SomeLabel; /* no equivalent */ break stmt! break; break; labeled break stmt! break SomeLabel; /* no equivalent */
  • 35. 35 C vs. Java: Details (cont.)! Java ! C ! return stmt! return 5; return; return 5; return; Compound stmt (alias block)! { statement1; statement2; } { statement1; statement2; } Exceptions! throw, try-catch-finally /* no equivalent */ Comments! /* comment */ // another kind /* comment */ Method / function call! f(x, y, z); someObject.f(x, y, z); SomeClass.f(x, y, z); f(x, y, z);
  • 36. 36 Example C Program! #include <stdio.h> #include <stdlib.h> const double KMETERS_PER_MILE = 1.609; int main(void) { int miles; double kmeters; printf("miles: "); if (scanf("%d", &miles) != 1) { fprintf(stderr, "Error: Expect a number.n"); exit(EXIT_FAILURE); } kmeters = miles * KMETERS_PER_MILE; printf("%d miles is %f kilometers.n", miles, kmeters); return 0; }
  • 37. 37 Conclusions! • Getting started with C! • C was designed for system programming! • Different design goals from of Java! • Explains many of Cʼs eccentricities! • Knowing Java gives you a head start at learning C! • C is not object-oriented, but many aspects are similar! • Getting started in the course! • Check out course Web site soon! • Study “Policies” page! • First assignment! • Establish a reasonable computing environment soon! • Instructions given in first precept!
  • 38. 38 Getting Started! • Check out course Web site soon! • Study “Policies” page! • First assignment is available! • Establish a reasonable computing environment soon! • Instructions given in first precept!