setenv EDITOR vi (or setenv EDITOR gnu-emacs) xobjectcenterThen, when you want to edit your file, pull down the "File" menu, and let go of the mouse on "Edit". This will ask you for the name of a file, and then bring up your editor. From then on, ObjectCenter will know about your editor, and automatically take you to the line that is causing a warning or error message.
Note: If you forget to "setenv EDITOR gnu-emacs" before entering ObjectCenter, you should exit ObjectCenter and start over.
One possibility is that ObjectCenter is detecting accesses to uninitialized data that the compiler doesn't check for. It may be that your program worked when compiled because the data happened to have had initial value zero. For example:
street_seg *intersections[20]; // doesn't initialize array
if (intersections[0] == NULL) // but we might get lucky
{
intersections[0] = new street_seg;
}
If you're developing the program using something other than
ObjectCenter and then doing your final work with ObjectCenter, it's a
good idea to turn on all the warnings your initial compiler provides.
With gcc, this is done with the -Wall
option:
gcc -WallNote, however, than sometimes compilers give false warnings!
Consider this simple function example:
int
average(int a, int b) { // this is called the function DEFINITON
return (a + b) / 2;
}
For every function you should have a function declaration
(also known as a function prototype) at the top of the file or
in a header file. A function declaration is basically the part before
the first brace with a semicolon following it. What this does is tells
compiler what type function is and what type and how many arguments to
expect, which it needs to know before the function is used. Don't need
for main. Example of declaration:
int average(int a, int b); // don't actually need var namesActually this isn't needed at top of file, only sometime before it's called. But top of file is generally good so you can see at a glance what all your subroutines are. As programs get larger, will create a ``header file'', like ``blah.h'', that holds all this sort of header info.
A few general rules for declaring functions:
Similar rules apply also to variables. Look at the following example:
int my_var; // definition of global variable external int my_var; // declaration
Rules for declaring variables:
The following program computes Fibonacci numbers recursively (but not particularly efficiently). Go through a small example of how this program would execute, showing the call stack after each recursive call.
int
Fibonacci1(int n) {
if(n <= 1) return 1;
else return Fibonacci1(n - 1) + Fibonacci1(n - 2);
}