Loading and Running Programs

The UCW (UnderC for Windows) console window allows you to enter C++ statements and UCW commands at the ;> prompt. Generally, expressions and statements are terminated with a semicolon; anything beginning with #, like preprocessor directives, and UCW commands are not. Warning and informational messages (including values of variables) in the console appear in green, and error messages appear in red.

Using the Clipboad with UCW

By dragging the mouse over the console to highlight it, you can mark an area for copying to the Windows Clipboard. After an area is highlighted, you can use Ctrl+C to copy the content as you would in other Windows applications. If you want to save the whole session to a file, you can use the log command (#log). It is also possible to execute commands and statements by pasting them into the console with Ctrl+V.

Exiting UCW: #q

Normally, you use #q to quit a session, but there is also #ql, which means “quit and write to the log file.” The resulting automatic log files are made up of the date and time, like this: 0805-1645 (which represents month, day, hour, and minute).

Changing and Displaying the Working Directory: #cd, #pwd

It is useful to know where you are. Any program has a current working directory, which determines the default place where files will be found. UnderC has a command #pwd that will tell you what the working directory is, and a command #cd that works like the DOS or UNIX command of the same name:

;> #pwd
C:gcc	est
;> #cd c:olshucwexamples
;> #pwd
c:olshucwexamples
;> #cd /gcc/test
;> #pwd
c:gcc	est
;> #cd ../bin
;> #pwd
c:gccin

In Windows programs, note that you can actually use the old UNIX slash (/) instead of the backslash when writing paths to files. The backslash () is only really necessary at the DOS or NT command prompt. You should use / in your paths if you want your programs to be portable.

Loading Code and Running Programs: #x, #l, #r

You can execute system commands by using the execute command (#x). For example, #x dir /w *.cpp lists all C++ source files.

You must load code before you can run it, and this is the job of the #l command, which is usually followed by the source file. The source file can have any extension you like, but most source files end in .cpp or .h. If you have files that contain UnderC extensions, then the convention is to use .uc, to distinguish the file from files that are compatible with the standard C++ language. UnderC stops when it hits the first error because it concentrates on sorting out one error at a time. (Errors in C++ files often cause a cascade of unrelated errors after the first fault.) Warnings are not fatal, but they usually try to tell you something. Error messages will tell you the file and the line number where the error was encountered, as in this example:

;> #l inc1.cpp
inc1.cpp 32:parse error
inc1.cpp 32:Cannot find 'w'

If the #l command is not followed by a file, UCW assumes that you are reloading the last file.

When code is loaded and compiled, it can be run in two ways. First, by typing an expression that involves a function, you can exercise each function in the file. Second, if the file contains a main() function, you can run the program by using #r, followed by the command-line arguments, as you would type them at a Windows command prompt.

Of course, you can just type main(); at the ;> prompt, but using #r has several advantages: First, the program input and output both occur in a separate console window, which you can interrupt by using the stop command (#s) if you get into an infinite loop. Second, you can also inspect program variables from the ;> prompt if they are not local to some function. Therefore, it is useful keeping some variables global while you are debugging a program.

There are no restrictions on what you can do when a program is running. For instance, say your program consists of the file one.cpp, which exports do_it(), and main.cpp, which calls do_it() by using values that are read in from standard input. After loading both of the files, you can run the program and exercise do_it(); at any point, you can modify and reload one.cpp without having to stop the program. A rule of thumb is that you should not modify the function you are currently running. You can get away with modifying main.cpp in this case, but the program will probably crash (albeit rather harmlessly) when main() gets to the end. You can modify any global variables at any point.

Inspecting and Browsing symbols: #v, #d, #lv

Several UCW commands are useful in a number of situations. The module command (#mod) has two forms (a module is another name for a loaded C++ source file.) If you type #mod without parameters, you get a list of all files currently loaded. If you give #mod the name of a function, it will tell you in which module that function is defined and at which line.

The variable inspect command (#v) gives you information about a symbol, if it exists. It tells you the type (and size) of a variable, as well as the prototypes available for a function name—(there can be a number of overloaded versions of the function). You can use the scope operator (::) to qualify the reference to a method or a function within a namespace. The following are the usual prototypes available for the overloaded operator<<, and the definition of string::npos:

;> #v operator<<
VAR ostream& operator(ostream&,int) << size 4 offset 9303040
ostream& operator<<(ostream&,int)
ostream& operator<<(ostream&,double)
ostream& operator<<(ostream&,float)
ostream& operator<<(ostream&,const char*)
ostream& operator<<(ostream&,_Endl_&)
ostream& operator<<(ostream&,void*)
ostream& operator<<(ostream&,char)
ostream& operator<<(ostream&,const string&)
;> #v string::npos
VAR const int string::npos size 4 offset 3012
2147483647 was value

The display structure command (#d) is used to inspect the members of a structure, and the list variables command (#lv) will show the currently defined variables in scope:

;> struct Point {  int x,y; };
;> Point p;
;> p.x = 10; p.y = 20;
(int) 10
(int) 20
;> #d p
(int) x = 10
(int) y = 20
;> int x=1,y=2,z=3;
;> #lv
(int) _xo_ = 0
(Point) p = Point { }
(int) x = 1
(int) y = 2
(int) z = 3
;>

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.12.163.175