QUALIFYING VARIABLE NAMES
PRODUCT : TURBO C NUMBER : 455
VERSION : 2.0
OS : PC-DOS
DATE : OCTOBER 31, 1988 PAGE : 1/3
TITLE : QUALIFYING VARIABLE NAMES
The subsection "Qualifying Variable Names" on page 57 of the
Turbo C User's Guide is inaccurate. Use the following
information as documentation:
There are three typical situations in which it is desirable to
fully qualify a variable name used in an expression.
o To qualify a static variable in another module, use the
following syntax:
.<module name>.<variable name>
o To qualify a local variable in a global function, use the
following syntax:
<function name>.<variable name>
o To qualify a local variable in a static function, use the
following syntax:
.<module name>.<function name>.<variable name>
The function name is only used when looking at a variable local
to the function. For example, suppose your program contains two
modules (FIRSTMOD, MYSUBS):
/* FIRSTMOD.C */
int a = 1;
main()
{
int b = 2;
myfunc();
printf("%d", i);
}
/* MYSUBS.C */
static int e = 3;
static void localfunc(void)
{
int d = 4;
PRODUCT : TURBO C NUMBER : 455
VERSION : 2.0
OS : PC-DOS
DATE : OCTOBER 31, 1988 PAGE : 2/3
TITLE : QUALIFYING VARIABLE NAMES
printf("End of the road\n");
}
void myfunc(void)
{
int c = 5;
localfunc();
}
To watch the global variable a, use:
a
To watch the local variable b in main, use:
main.b
To watch the local variable c in myfunc, use:
myfunc.c
To watch the local variable d in the static function localfunc,
use:
.mysubs.localfunc.d
To watch the static variable e in module2, use:
.mysubs.e
The necessity of qualifiers will depend on the current
instruction pointer. For instance, if your program is running in
main, it is unnecessary to qualify the variable b with the
function name main. Likewise, if your program is running inside
the MYSUBS module, it is unnecessary to qualify the variable e
with the module name.
Additionally, it is not possible to watch an auto (local) in an
inactive scope. Since the function myfunc calls localfunc, it is
possible to watch the local variables of myfunc from localfunc --
the variables in myfunc are not removed when localfunc is called.
However, once myfunc returns to main, it is no longer possible to
PRODUCT : TURBO C NUMBER : 455
VERSION : 2.0
OS : PC-DOS
DATE : OCTOBER 31, 1988 PAGE : 3/3
TITLE : QUALIFYING VARIABLE NAMES
view its local variables -- local variables are discarded when
the function in which they are located returns to the calling
function.
DISCLAIMER: You have the right to use this technical information
subject to the terms of the No-Nonsense License Statement that
you received with the Borland product to which this information
pertains.
Comments
Post a Comment