lect09 - CMSC 216 Introduction to Computer Systems Lecture...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CMSC 216 Introduction to Computer Systems Lecture 9 Pointers Jan Plane & Pete Keleher {jplane, pete}@cs.umd.edu Administrivia • Project 2 due soon • Exam #1 – Thursday, October 6 in Lecture • Read Reek, Chapter 6: Pointers 2 P OINTERS Chapter 6, Reek 3 Last Time: An array of pointers char *arg_vector = { "prog", "1", "two", "THREE", "-4", NULL }; • argv looks just like this, including the NULL at the end 4 prog\0....... 1\0.......... THREE\0...... two\0........ -4\0......... 1056 1192 1324 1584 1776 1056 1192 1584 1324 1776 0 arg_vector More examples of pointers • Program: #include <stdio.h> int main() { int arr = {2, 3, 5, 8, 13}; int *ptr = &arr[2]; printf("%d\n", ptr[2]); printf("%d\n", ptr[-1]); printf("%d\n", *(arr + 3)); printf("%d\n", ++*ptr); printf("%d\n", arr[2]); printf("%d\n", *ptr++); printf("%d\n", *ptr); printf("%d\n", arr[-1]); return 0; } • Output: 13 3 8 6 6 6 8 ????? 5 M AKE (Not in the textbooks) More examples of pointers • Program: #include <stdio.h> int main() { int arr = {2, 3, 5, 8, 13}; int *ptr = &arr[2]; printf("%d\n", ptr[2]); printf("%d\n", ptr[-1]); printf("%d\n", *(arr + 3)); printf("%d\n", ++*ptr); printf("%d\n", arr[2]); printf("%d\n", *ptr++); printf("%d\n", *ptr); printf("%d\n", arr[-1]); return 0; } • Output: 13 3 8 6 6 6 8 ????? 5 M AKE (Not in the textbooks) 6 Separate Compilation • Placing code across several files allows us to update only parts of the object code for a program when changes occur • We have been just compiling everything into an executable, bypassing the object code step • Ex. from project #1: gcc -c puzzles.c gcc -c public01.c gcc -o public01 public01.o puzzles.o • Now, if we change puzzles.c , we only need to recompile half our program, and then link the object files together 7 The make utility • Using make helps automate separate compilation, using a Makefile we write • The Java compiler can tell if it has to compile other classes than the one you've told it to compile; C compilers can't • Typing out the commands to build C programs is error-prone and can get annoying, especially if using several command-line options • Note: this is a compressed description of Make; full manual is available online off of course information page 8 Example • Recall Project #1 again: 9 publicX.c : #include <stdio.h> #include "puzzles.h" int main() { size_t x = sizeof_long(); ... if (is_nonzero(0)) ...; else ...; ... return 0; } puzzles.c : #include "puzzles.h" int is_nonzero(int a) { ... } size_t sizeof_long() { ... } ... puzzles.h : #include <stddef.h> int is_nonzero(int); size_t sizeof_long(); ... Dependencies • Since main() is in publicX.c , we'll name the program publicX • What needs to be compiled if ......
View Full Document

{[ snackBarMessage ]}

Page1 / 15

lect09 - CMSC 216 Introduction to Computer Systems Lecture...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online