ID Number: Q67007
2.x 3.00 3.10 3.11 3.14 | 2.x 3.00 3.10 3.11 3.12 3.50
MS-DOS | OS/2
docerr
Summary:
Page 201 of the "Microsoft C Advanced Programming Techniques" (APT)
manual that accompanies Microsoft C versions 6.0, 6.0a, and 6.0ax
states that "any C function in your program (whether user-written or
from the library) can be called from the Command window or the Watch
window."
This statement is not completely true. Actually, only functions
compiled with full CodeView symbolic information can be called. This
restriction eliminates all of the C run-time functions from being
carried out in this manner because they contain no symbolic
information. A simple example of how to call a C run-time function is
shown below.
More Information:
If an attempt is made to carry out a function that has not been
compiled with symbolic information via the Command window, the
following error will be displayed in the Command window:
CV1017 Error: Syntax error
In CodeView versions 2.x, an "unknown symbol" error is displayed in
the Command window.
If an attempt is made to add the function to the Watch window via the
Watch menu and the "Add Watch" command, CodeView will ignore the entry
and beep. In versions 2.x, CodeView will give an "unknown symbol"
error.
The APT gives an example of calling a C function from the Command
window via the following command:
?funcname (varlist)
This command will only invoke the function and display its return
value in the Command window. To add the function to the Watch window,
a slightly different command must be used:
w?funcname (varlist)
The function name can also be added to the Watch window by choosing
the Watch menu and the "Add Watch" command, and typing only the
function name plus its variable list enclosed in parenthesis. Neither
"w" or "?" is needed in this situation.
It is important to note that you should be sure that the screen
flip/swap option on the Options menu is turned on if the function you
run performs any screen input or output.
For example, if you want to call a C run-time function or any other
function that does not contain CodeView symbolic information, you must
create a shell function that calls the desired function itself and
gives the same return value.
Therefore, if you wanted to call the C run-time function sqrt()
directly from the CodeView Command window or Watch window, create a
shell function that resembles the following:
#include <math.h>
double my_sqrt(double x)
{
return(sqrt(x)) ;
}
Then compile this function with CodeView information by compiling with
the /Zi switch, and link it into your program being sure to include
/CO in your link command. Note that your program does not need to make
a call to the function in order for it to be available for direct
execution.
To carry out this function from the Command window, enter the
following command:
?my_sqrt(4.0)
The return value should be displayed on the next line in the Command
window. In this example, 2.0000000000000 should be displayed as a
result of the square root of 4.0.
To add the function to the Watch window via the Command window, enter
the following command:
w?my_sqrt(4.0)
The function could also be added to the Watch window by choosing the
"Add Watch" command from the Watch menu and entering the following at
the Add Watch prompt:
my_sqrt(4.0)
When a function is added to the Watch window, that function is
carried out any time the Watch window is updated.
Although these examples show a constant value as the parameter to the
function, any variable that is in scope at the time could be entered
as a parameter.
Additional reference words: 2.0 2.00 2.1 2.10 2.2 2.20 2.30 2.30 2.35
3.0 3.00 3.1 3.10 3.11 3.12 3.14 3.5 3.50 6.00 6.00a 6.00ax