|
|
|
|
Section 01, 3/31/11
Lecture Material
Section slides: PDF
Notable questions from section
- A student asks: I tried the erroneous code from the slides, and it did not crash on my
machine. Why? This is a good example of how unpredictable memory errors in C can be. The
bug in the code is that we iterate off the end of the argument array, and access undefined
memory. When I (Colin) ran the example from the slides on my machine, the memory just past the
end of the array was full of zeros, so it crashed when it tried to read the string at address 0
(NULL). On other machines, that memory may have different contents that specify an address that
is valid, but contains unknown data. In that case,
atoi() sees that the first byte
is not a character for a numeric digit (0-9), and simply returns 0, yielding the correct result.
- When Eclipse was mentioned in class as a C/C++ editor, several students balked. I've
looked into this since lecture, and yes, setting up Eclipse to work with C/C++ code, especially
integrating with
make and gdb , appears to be a nightmare, so we do not
recommend this.
Editor Tutorials
Vim and Emacs are the quintessential "UNIX-y" editors, but you are free to use any editor you're
comfortable with.
- gedit: gedit is a pretty simple editor, so hopefully not much guidance is necessary on its
use. It does, however, have some integration with
make : Go to
Edit->Preferences, go to the Plugins tab, and check the box for the External Tools plugin.
Now either holding down Control and pressing F8, or going to Tools->External Tools->Build
will run make (with the default target).
- emacs: Emacs is a pretty advanced editor, but has good integration with tools we'll
be using this quarter. One of its design goals is that users should never have to take their
hands off the keyboard (for example, to use the mouse). Emacs has a built-in tutorial to learn
the basics, which you can start by typing Control-h then t (press h while holding control, then
release all keys and press t). There is a good tutorial on using GDB within emacs here. And if you go through that stuff and
want even more, there's a blog full of emacs tips at http://www.masteringemacs.org/.
- vim: Vim, like emacs, was designed to minimize any need to remove your hands from the
keyboard. It has a steeper learning curve, but many people find it very efficient to use once
they learn the basics. Vim also has its own introductory tutorial, accessible through the help
system, or directly by running the command
vimtutor in a shell (you might want to
make sure your terminal is a bit tall to make sure the instructions for moving through files fit
on the first screen of text). There is also a semi-graphical version, gvim that
provides menus to access some of the more advanced functionality without knowing all of the
keyboard commands.
|