ObjectCenter Tutorial

This is the html version of the Objectcenter tutorial. It does not include any of the screen-dump pictures. See the postscript file for the "official" version.


This is an introduction to ObjectCenter, a graphically oriented C and C++ programming environment. ObjectCenter has many features: it is a large and comprehensive system. You will not care about many of these features.

The most important thing to you is that ObjectCenter performs static and run-time error detection. This means that you will have an easier time debugging your programs. If you have a bad pointer (and you will probably have many as long as you program in C or C++) ObjectCenter will make it easier for you to catch it and fix it.

This tutorial will first discuss how to start up ObjectCenter, then will walk you through some simple C++ programming examples, explain how to use the built-in debugger, discuss additional features, and tell you how to save an ObjectCenter session and quit. Feel free to deviate from the tutorial steps at any point. Try playing around: it's a lot more useful than following the tutorial steps like an automaton.

Starting Up

If you want to edit files within ObjectCenter you will need to set up your EDITOR environment variable. It may already be set. To check, type the following in your X terminal window (assume the prompt is %):

% printenv EDITOR

If it is not set to anything, or if you want to change it to, say, gnu-emacs, input:

% setenv EDITOR gnu-emacs

Now you are able to use your favorite editor from within ObjectCenter. We have tried using gnu-emacs in this fashion, and we have noticed that it doesn't work exactly like gnu-emacs. You cannot move the cursor around with the mouse and the line of reverse video at the bottom of the screen sometimes is not in reverse video (that can be rectified by doing Control-l). But other than this it works fine. You also get a special ObjectCenter menu by pressing the right mouse button (unless your buttons are mapped differently from usual).

You can also bypass ObjectCenter and run your editor separately. This way the mouse buttons will work as you expect. One disadvantage of doing this is that you have to make sure you are not editing the same file in two different places at the same time (in your editor and inside of ObjectCenter).

Note: You can only use emacs or vi from within ObjectCenter. If you want to use ez you must run it separately.

Start ObjectCenter with the command:

% xobjectcenter &

(The & makes it run in the background.) You will get an objectcenter window (after a while!). If you are using one of the newly installed Sun workstations, type objectcenter rather than xobjectcenter. The Sun's run a new version of ObjectCenter; this tutorial describes the Dec workstation version.

This Main window is made up of five parts, in order from top to bottom:

Note: There is also a character-based version of ObjectCenter, called objectcenter on the DECstations. You can use it instead of the X version, if you choose, but it doesn't provide you with a nice mouse-based interface.

Doing Simple Things

You can just type C or C++ expressions directly into ObjectCenter, using the bottom panel (the Workspace panel). Try the following in there, and compare the result you expect with the result you actually obtain:

2 + 3;
int x;
x = 1;
x = x + 1;
int y = x;
x = 23;

Important: You can also enter function and type definitions this way. However, ObjectCenter doesn't allow you to redefine a function or a type. In fact, if you define and redefine a function, the old definition will be used, and ObjectCenter will not give any error message. To remove the old definition, type: unload workspace which will remove all the function and type definitions made in the workspace.

Now the time has come to take the big step and write a whole program. It will be very small. You can enter the new program in the Source panel directly, but it's probably better to use your favorite editor, and just use the Source panel to look at files while executing, or to make simple changes. (Note than whenever you are in the Source panel you can press the right mouse button to get an Edit Menu, which covers most file-related operations.) Either edit the file using a separate editor, or type in the workspace panel:

edit simple.c

You can also tell ObjectCenter you want to edit something by choosing File->Edit from the menu. Most commands in ObjectCenter can be executed both from the prompt in the Workspace panel, or from the appropriate menu. In some cases there is also the choice of using the buttons in the Options panel.

Note: Both of the above commands tell ObjectCenter you want to edit file simple.c in the current directory. You can change directory using the Unix command cd in the Workspace panel. ls and pwd also work there.

Type in the program below in the editor. You don't have to type in the comments (the text between /* and */).

 #include <stdlib.h>     /* standard C library. Always good to include. */
 #include <stdio.h>      /* Standard C I/O library: contains "printf". */
 int times2 (int x)      /* a function that doubles an integer    */
 {                       /* this is not really necessary; it just */
    return(2*x);         /* shows how to define a function        */

 int main(void)          /* main function; any C program must have one  */
    int y = 5;           /* declare y to be an integer and = 5   */
    int times2(int);     /* declare times2 function before using */

    printf("5 times 2 is %d\n", times2(y));   /* output 5 times 2 is 10 */
    return 0;                                 /* exit gracefully        */

Save the program as simple.c. You can load simple.c into ObjectCenter by typing: load simple.c in the Workspace panel. If you want to, you can list simple.c in the Source panel by typing: list simple.c in the Workspace panel.

Note: ObjectCenter starts up in C++ mode. C++ contains C as a subset, so (as long as you don't use certain reserved words as variable names) your C programs are also valid C++ programs. At the end of this document is a list of C++ reserved words.

Very Important: If ObjectCenter detects an error while loading the file (e.g. an obvious typo, an undefined variable or function) you will see in the Message panel a listing of the number of errors encountered. Clicking on the little ``folder'' icon will actually display the errors. If ObjectCenter detects errors while loading a file, the file remains unloaded. Subsequent attempts to access functions defined by that file will generate messages that functions are undefined (e.g. run: 'main' is undefined). If you see messages like this after loading your file, check the Messages panel for errors encountered during loading. (Try putting some garbage in your file simple.c and loading it to see this effect.)

Now, assuming there were no errors, you can just click the run button to run your program. Or, you can type run in the Workspace panel. This brings up a Run window. (You don't have to press run again in the Run window - your program is already running.) If you want to run it again, you can go ahead and click run in the Run window. You can get rid of the Run window by clicking dismiss.

Note: You can also type: main(); in the Workspace panel to run your program-this does the same thing but doesn't bring up a Run window. Remember that whenever you enter C/C++ code directly into the Workspace panel, you must end with a semicolon.

Important: One of the best features of ObjectCenter is that you don't have to run the whole program. You can also execute individual functions within your program in the Workspace panel. For example, try using your times2 function in the Workspace panel. When developing code it is good to test the components as you write them.


For those familiar with gdb, ObjectCenter provides the same type of functionality but with the addition of a graphical interface. You can set breakpoints, watchpoints (which interrupt program execution when a variable or address is modified), examine the run-time value of a variable, etc. ObjectCenter also provides actions, which are breakpoints and watchpoints that execute any C or C++ code that you specify. This tutorial only covers simple things like setting and removing breakpoints. For the more advanced features, see Chapter 6 of Using ObjectCenter.

As mentioned before, ObjectCenter will do run-time error checking. So, if you have a stray pointer you will be told where it happens, instead of getting an obscure error message from the shell. In this section you will add some erroneous code to your simple.c file, then ``find'' it, and then fix it. Change the main function so it looks like the one below (again, skip the comments):

 int main(void)   
    int times2(int);     /* declare times2 function before using it     */
    int array[5], i;     /* declare integer array of size 5 and index i */

    for (i=0; i<5; i++)             /* initialize array to: 5,6,7,8,9   */
      array[i] = i+5;

    for (i=0; i<=5; i++)            /* compute array[i]*2 for all elems */
      printf("%d times 2 is %d\n", array[i], times2(array[i]));

    return 0;                                 /* exit gracefully        */

After making the changes, reload the code. You can hit the build button (or type ``build'') to reload. Run it. You should get an error, with the offending line highlighted in the Source panel.

Aha! We have gone past the edge of the array. The array is of size 5, going from 0 to 4. and we are trying to index array[5]. You can check the value of i by highlighting the variable i with the left mouse button within array[i] and pressing Shift-left mouse button. This brings up a little window with the value. When you move your mouse the window disappears. Doing Shift-middle mouse button after highlighting a variable shows its definition. Try both for i, array[i], and array.

Note: You don't always have to highlight a variable to do Shift-left or middle mouse button. If it's a variable whose name is a single word, like i or array, it's sufficient to have the mouse on top of it. However, if it's something like array[i], you need to highlight it first. Try it.

Let's set a breakpoint on this offending line so we can check the value of i before it tries to access outside the array. Type reset (in the workspace) to end program execution. Move the mouse to the left of line 17. You will note that at some point the pointer becomes a stop sign. Click the left mouse button. A stop sign is now on the line. Now click run again. Check the value of i, and of array[i]. Click step repeatedly to step through the program line by line, or continue to get directly to the next breakpoint. Try both. Keep checking the value of i. At some point you will note that i = 5 and array[5] is undefined.

We have to prevent i from getting to 5. This is simple. Change the beginning of the second for loop to read for (i=0; i<5; i++), just like the first loop. Save and reload. Remove the breakpoint by doing the same thing you did to put it there (go to the left of line 17 and when the cursor changes to a stop sign click the left mouse button). The breakpoint is gone. Run the program again. This time it should work.

Additional Features

ObjectCenter provides many additional facilities for viewing program information. We will only discuss a few of them in this section.

Xref allows you to see graphically, for any of the functions in your program, what other functions it calls, and what global variables it uses. This is useful when you have complicated programs, and you need to get an overview.

Let's use the Cross-reference browser for our little example, simple.c. Go to the Menu and choose Information->xref. Type main as the function name and click Xref. Double-clicking on any function in there runs Xref on that function. This provides an easy way to navigate around your program.

Another useful feature when you have large programs is the Project browser. Choose Project->browse from the Menu. In a separate window you will get a listing of the various components of your program, and whether they are included in source, object, or library form. Clicking on the folder icons at the far left opens the files and shows you what is defined inside.

Another useful feature in ObjectCenter is a method to visually navigate around a linked list using Information->display. Read up on this and other features in Chapter 7 of Using ObjectCenter.

Saving a Session and Quitting

You can exit ObjectCenter by typing: quit in the Workspace panel (you can also choose File->quit from the menu). You will have three choices (plus cancel):

A project file contains a snapshot of the state of your session with ObjectCenter: what files are loaded, where the breakpoints are, etc. Run-time information (like definitions made in the Workspace panel) is not included.

You can save a project file at any point (not just when quitting) by typing: save <file> (replace ``<file>'' by the name of your file) in the Workspace panel. You can start up ObjectCenter with a saved project file by typing: xobjectcenter <file>.

An image file is a more detailed snapshot than the project file, containing everything about your session (including window layout). You can also save an image at any point in time with save image <file>, and you can start up ObjectCenter with an image file by giving it as an argument.

C++ reserved words

Every keyword, or reserved-word in C is also a keyword in C++. The following are extra keywords in C++ that have no meaning in C.

asm, delete, if, return, try
auto, do, inline, short, typedef
break, double, int, signed, union
case, else, long, sizeof, unsigned
catch, enum, new, static, virtual
char, extern, operator, struct, void
class, float, private, switch, volatile
const, for, protected, template, while
continue, friend, public, this,
default, goto, register, throw

Thu Jan 26 10:45:56 EST 1995