/****************************************************************/ /* Purpose: Example illustrating separate compilation and */ /* use of globals variables. */ /* Template for test driver for GCS module. */ /* Name: M. Overstreet */ /* Date: 4 Sept. 2003 */ /* Description: Initializes a few global variables, calls tsp, */ /* which modifies them, then prints them again. */ /* If the linkage is set up correctly, the second */ /* set of values will have been modified by tsp. */ /****************************************************************/ /****************************************************************/ /* Listing Contents: */ /* Reuse instructions */ /* Compilation instructions */ /* Source code */ /****************************************************************/ /****************************************************************/ /* Reuse Instructions */ /* Program is so short, reuse opportunities are limited. */ /****************************************************************/ /****************************************************************/ /* Compilation Instructions */ /* Compiled under Solaris with */ /* g++ -o globals -g globals.cpp tsp.o */ /* Note that tsp must be compiled first */ /****************************************************************/ /****************************************************************/ /* Precondition: None. Program reads no data. */ /* Postcondition: Values of selected globals have been changed */ /* by external tsp code. */ /* This is demonstrated by printing them before */ /* and after the tsp call. */ /****************************************************************/ using namespace std; #include #include "/home/cs350/term.projects/include.files/external.h" #include "/home/cs350/term.projects/include.files/guidance_state.h" #include "/home/cs350/term.projects/include.files/run_parameters.h" #include "/home/cs350/term.projects/include.files/sensor_output.h" struct guidance_state gs; struct external ex; struct run_parameters rp; struct sensor_output so; extern void tsp(); int main() { // Initialize a few of the many global variables. gs.cl = 1; ex.ar_counter = 1; rp.a_scale = 1; so.td_sensed = 1; // note td_sensed is declared char, but is to be used like an int. // Print them. cout << "gs.cl = " << gs.cl << endl; cout << "ex.ar_counter = " << ex.ar_counter << endl; cout << "rp.a_scale = " << rp.a_scale << endl; cout << "so.td_sensed = " << so.td_sensed << endl; // Call tsp. cout << "Calling tsp." << endl; tsp(); // Reprint vars (to see if they changed). cout << "gs.cl = " << gs.cl << endl; cout << "ex.ar_counter = " << ex.ar_counter << endl; cout << "rp.a_scale = " << rp.a_scale << endl; cout << "so.td_sensed = " << so.td_sensed << endl; }