CS 440 - Fall 2005 | Assignment 1 | Aug. 30, 2005 |
This assignment is due by the start of class on Wednesday, Sept. 7. Kill some bits, save a tree, and save me having to decipher everyone's handwriting. Please type up your solutions and email them to me.
The source code for this assignment can be found in ~bwall/CS440/assign1.tgz. Extract the source into your own directory, compile and link each of the source files using gcc, and run the resulting executable. Each one will either crash and burn with the ever-so-helpful Unix segmentation fault or will generate some unexpected results.
Problems 1 through 10: for each of the err*.c programs, figure out what is causing the error in the program. Fix it in some way and make sure that the program will run successfully. Record what was wrong with the code, why it manifested itself the way it did (i.e. what did the error cause to happen in the code), and what you did to repair it.
Each question is worth three points - so you can get partial credit for each one. For full credit, make sure you are fairly explicit in explaining why the error programming error caused the erroneous results; I'd like to see how well people understand what.s going on in the machine while the program is running.
Bonus questions. Feel free to skip these; if you have the time or inclination, they are worth bonus points that can carry over between assignments. (So if you get everything right on this assignment and get all the bonus points, you can get more than 100% for the assignment and offset some mistakes on another assignment.)
Note that this error doesn't always manifest itself the same way on other variants of Unix - but on Linux in particular, it's been a source of a lot of hard-to-find errors I've had to track down.
Run this program on each of the err*.c source files and see what it generates. Note that it will spit out plenty of other warnings too - try to sift out the one that was actually causing the error. Record the pertinent warning (or warnings) for each of the programs.
NOTE: you'll notice from the code that I'm pretty consistent in the way I format my source code, even for a little short throw-away program. If you're going to be writing code for a living, it's important to do a professional job of it. And that means not just making it run, but making it presentable. Trust me, in the future, when someone points you to a pile of source code that you have to debug and/or maintain, you'll really be hoping that the original author did the same. Earn some good karma and always write clean code.
I am going to apply this to your programming assignments - part of the points for each assignment will be based on how well-formatted and consistent your code is. That's not to say that I expect everyone to use the same coding style I do; a lot of programmer "holy wars" have been waged over the years about exactly what the "right" style is, and we're sure not going to answer that question. But you need to pick a style and apply it consistently.
In case you need it, here's a link to the PDF version of the assignment.