Download presentation
Presentation is loading. Please wait.
Published byAleesha Louise Paul Modified over 8 years ago
1
3/8/2007 Copyright (c) 2007 by Adcock, Bucci, Heym, Hollingsworth, Long, & Weide 1 Which Pointer Errors Do Students Make? Bruce Adcock 1 Paolo Bucci 1 Wayne D. Heym 1 Joseph E. Hollingsworth 2 Timothy Long 1 Bruce W. Weide 1 1 Dept. of Computer Science & Engineering The Ohio State University Columbus, Ohio 2 Dept. of Computer Science Indiana University Southeast New Albany, Indiana
2
3/8/2007 Copyright (c) 2007 by Adcock, Bucci, Heym, Hollingsworth, Long, & Weide 2 What’s New State machine model for explaining C++ pointer errors Checked Pointers for C++: Provide immediate feedback to students when a pointer error occurs Provide error data Data on student pointer errors
3
3/8/2007 Copyright (c) 2007 by Adcock, Bucci, Heym, Hollingsworth, Long, & Weide 3 Questions to Be Answered What are the most common pointer errors made by student programs? How common are problems with storage leaks? How common are problems with dereferencing dead pointers?
4
3/8/2007 Copyright (c) 2007 by Adcock, Bucci, Heym, Hollingsworth, Long, & Weide 4 The Challenge of Pointers Difficult for students understand and consequently for teachers to explain Cause of many errors, not just in CS2, but also later in curriculum Cause of many bugs in “release-quality” commercial software errors may be manifested only much later in execution errors may be difficult to reproduce errors may not be noticed until long after software is released
5
3/8/2007 Copyright (c) 2007 by Adcock, Bucci, Heym, Hollingsworth, Long, & Weide 5 Out of scope AliveNull Dead Alive - the variable refers to memory that the storage management system has given to the program, i.e., the program “owns” that memory. Dead - the variable refers to memory that the storage management system has never given to the program or has reclaimed from it, i.e., the program does not “own” that memory. Different States of a C++ Pointer
6
3/8/2007 Copyright (c) 2007 by Adcock, Bucci, Heym, Hollingsworth, Long, & Weide 6 Safe Transitions of a C++ Pointer Out of scope AliveNull Dead Declare } } New Delete NULL *
7
3/8/2007 Copyright (c) 2007 by Adcock, Bucci, Heym, Hollingsworth, Long, & Weide 7 Unsafe Transitions of a C++ Pointer Out of scope AliveNull Dead Declare } } New Delete NULL * * * Delete } New NULL
8
3/8/2007 Copyright (c) 2007 by Adcock, Bucci, Heym, Hollingsworth, Long, & Weide 8 Dangerous Moves Out of scope AliveNull Dead * * Delete Red transitions are never safe Yellow transitions can be unsafe Black transitions are always safe } New NULL
9
3/8/2007 Copyright (c) 2007 by Adcock, Bucci, Heym, Hollingsworth, Long, & Weide 9 Template wrapper for raw C++ pointers Work exactly like raw C++ pointers for black transitions Automatically detects red transitions Automatically detects unsafe yellow transitions Checked Pointers
10
3/8/2007 Copyright (c) 2007 by Adcock, Bucci, Heym, Hollingsworth, Long, & Weide 10 During Developing and Testing Checked Pointers “Hammer” the Developer Halt program Output an appropriate error message to the tester Record the type of error in a log file
11
3/8/2007 Copyright (c) 2007 by Adcock, Bucci, Heym, Hollingsworth, Long, & Weide 11 A Simple Demonstration Applying Checked Pointers to a defective implementation of an unbounded queue The Set-up: Queue has one data member called “head” Empty queue – head stores NULL Non-empty queue – head stores address to 1 st node Last node’s “next” stores NULL
12
3/8/2007 Copyright (c) 2007 by Adcock, Bucci, Heym, Hollingsworth, Long, & Weide 12 The Most Widely Made Errors “Top 5 List” Type of Error Students Making Error Percentage of All Errors Creating memory leak by ptr leaving scope74%21% Dereferencing dead ptr by using * or -> 70%33% Creating storage leak by using = (assignment) 61%18% Dereferencing null ptr by using * or -> 57%16% Using dead ptr with !=30%5%
13
3/8/2007 Copyright (c) 2007 by Adcock, Bucci, Heym, Hollingsworth, Long, & Weide 13 Conclusions Approximately 80% of all errors might have gone undetected if not using the Checked Pointer Tool (see demo – “Release” mode) Almost 3/4 of all students created at least one version of a program with a storage leak Over 2/3 of all students created at least one version of a program with a dereferenced dead pointer
14
3/8/2007 Copyright (c) 2007 by Adcock, Bucci, Heym, Hollingsworth, Long, & Weide 14 Food for Thought If we do not teach our students to manage storage properly when there is no automatic garbage collector, then when faced with having to do it in the workplace (e.g., in C++ or C), most will lack adequate proficiency.
15
3/8/2007 Copyright (c) 2007 by Adcock, Bucci, Heym, Hollingsworth, Long, & Weide 15 Some Future Possibilities Three versions of Checked Pointers: 1. Log error, stop program and provide detailed error messages (as is done now) 2. Log error, stop program but provide “pointer error” as the error message 3. Quietly log error, but allow execution to proceed How does the developer’s debugging behavior differ under these three versions?
16
3/8/2007 Copyright (c) 2007 by Adcock, Bucci, Heym, Hollingsworth, Long, & Weide 16 Will Your Mileage Vary? Go to: www.cse.ohio-state.edu/sce/SIGCSE2007/ www.cse.ohio-state.edu/sce/SIGCSE2007/ There you’ll find: A copy of these slides Checked Pointers as implemented at: IU Southeast Ohio State Virginia Tech
17
3/8/2007 Copyright (c) 2007 by Adcock, Bucci, Heym, Hollingsworth, Long, & Weide 17 Q&A Time
18
3/8/2007 Copyright (c) 2007 by Adcock, Bucci, Heym, Hollingsworth, Long, & Weide 18
19
3/8/2007 Copyright (c) 2007 by Adcock, Bucci, Heym, Hollingsworth, Long, & Weide 19 Out of scope AliveNull Dead Declare } } New Delete NULL * * * Delete } New NULL Transitions of a C++ Pointer
20
3/8/2007 Copyright (c) 2007 by Adcock, Bucci, Heym, Hollingsworth, Long, & Weide 20 Transitions of a Java Reference Out of scope AliveNull Declare } New Delete NULL ** }
21
3/8/2007 Copyright (c) 2007 by Adcock, Bucci, Heym, Hollingsworth, Long, & Weide 21 Teaching C++: Is It Still Relevant? Monster.com search on Feb 22 for job title including C++ returned 857 job offers 2003 paper reports 30% of 424 programmer position ads in newspaper were for C++ (de Raadt, M., Watson, R., and Toleman, M. 2003. “Language tug-of-war: industry demand and academic choice.” In Proceedings of the Fifth Australasian Conference on Computing Education - Vol 20 (Adelaide, Australia), 137- 142) C++ reported as primary programming language in use in 53% of the 45 departments that responded to survey (151 departments were sent the survey) (McCauley, R. and Manaris, B., 2002, Comprehensive Report on the 2001 Survey of Departments Offering CAC - Accredited Degree Programs, http://www.cs.cofc.edu/~mccauley/TReports/2002-9-1.pdf)
22
3/8/2007 Copyright (c) 2007 by Adcock, Bucci, Heym, Hollingsworth, Long, & Weide 22 % of students who made each error at least once all pointer manipulations Out of scope AliveNull Dead declare } } New Delete NULL * * * Delete (65%) (4%) (3%) (10%) (75%) (47%) Dead/== or != (42%) Dead/== or != NULL (14%) Alive/ = (50%) } New NULL
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.