1.25.verification - Reasoning About Code 1/25/2010 int...

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

View Full Document Right Arrow Icon
Reasoning About Code 1/25/2010
Background image of page 1

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

View Full DocumentRight Arrow Icon
int deref(int *p) { return *p; }
Background image of page 2
/* requires: p != NULL */ int deref(int *p) { return *p; }
Background image of page 3

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

View Full DocumentRight Arrow Icon
int sum(int a[], size_t n) { int total = 0; for (size_t i=0; i<n; i++) total += a[i]; return total; }
Background image of page 4
int sum(int a[], size_t n) { int total = 0; for (size_t i=0; i<n; i++) total += a[i]; return total; }
Background image of page 5

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

View Full DocumentRight Arrow Icon
int sum(int a[], size_t n) { int total = 0; for (size_t i=0; i<n; i++) total += a[i]; return total; }
Background image of page 6
int sum(int a[], size_t n) { int total = 0; for (size_t i=0; i<n; i++) total += a[i]; return total; }
Background image of page 7

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

View Full DocumentRight Arrow Icon
int sumderef(int *a[], size_t n) { int total = 0, i; for (i=0; i<n; i++) total += *(a[i]); return total; }
Background image of page 8
int sumderef(int *a[], size_t n) { int total = 0, i; for (i=0; i<n; i++) total += *(a[i]); return total; } Woops! If (int)n < 0, i becomes negative, and a[i] is unsafe.
Background image of page 9

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

View Full DocumentRight Arrow Icon
int sumderef(int *a[], size_t n) { int total = 0; for (size_t i=0; i<n; i++) total += *(a[i]); return total; }
Background image of page 10
Background image of page 11

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

View Full DocumentRight Arrow Icon
Image of page 12
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/14/2010 for the course CS 161 taught by Professor Wagner during the Spring '10 term at University of Central Arkansas.

Page1 / 24

1.25.verification - Reasoning About Code 1/25/2010 int...

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

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