CS201J: Engineering Software, Fall 2002
|
Notes: Thursday Halloween 2002
Schedule
- Now: Problem Set 5: Part 2
- Tuesday, 12 November: Problem Set 6
- Thursday, 14 November: Exam 2 Out
- Tuesday, 19 November: Exam 2 Due
Null Pointer Dereferences
What can happen if a C program dereferences a null pointer?
How can we detect and avoid null pointer dereferences?
Memory Management in C
What happens if a program does not release the memory it allocates?
How can programmers document assumptions about memory management?
Malloc and Free/*@only@*/ /*@null@*/ void * malloc(size_t bytes); void free(/*@only@*/ void * ptr);Species Constructor/*@only@*/ Species Species_new (/*@only@*/ char *name, /*@only@*/ char *genome) { Species s = (Species) malloc (sizeof (*s)); if (s == NULL) { fprintf (stderr, "Out of memory in Species_new.\n"); exit(EXIT_FAILURE); } s->name = name; s->genome = genome; return s; }
University of Virginia Department of Computer Science CS 201J: Engineering Software |
Sponsored by the National Science Foundation |
cs201j-staff@cs.virginia.edu |