Debugging C++ Applications Using HP WDB (766162-001, March 2014)

HP WDB scope resolution operator, double colon (::) can also be used as WDB's own scope
operator as explained in the following text. The C++ scope resolution operator has the same
precedence as WDB’s own scope operator.
This section discusses the following topics:
HP WDB scope resolution operator” (page 8)
“C++ scope resolution operator” (page 9)
HP WDB scope resolution operator
HP WDB scope resolution operator is used to specify a variable in terms of the file or function,
where the variable is defined. Variables in expressions are understood in the selected stack frame.
The variable is visible or searched in WDB according to the scope rules of the programming
language from the point of execution in that frame. The variable can also be either global or
file-static.
Example 2 shows the usage of HP WDB scope resolution operator.
Example 2 HP WDB Scope Resolution Operator
1 void foo (int a)
2 {
3 bar (a);
4 {
5 int b = test ();
6 bar (b);
7 }
8 }
In this example, you can examine and use the variable a, whenever your program is executing
within the foo function. However, you can only use or examine the variable b while your program
is executing inside the block, where b is declared. However, you can refer to a variable or a
function whose scope is a single-source file, even if the current execution point is not in this file.
But it is possible to have more than one such variable or function with the same name (in different
source files). If that happens, referring to that name has unpredictable effects. If required, you can
specify a static variable in a particular function or file, using the colon-colon notations:
file::variable
function::variable
where file or function is the name of the context for the static variable. For file names, use '
' (single quotes) to ensure that the GDB parses the file name as a single word. For example:
$cat a.c
1 #include <stdio.h>
2
3 int x=10;
4
5 void func(void);
6
7 int main() {
8 int x=20;
9 func();
10 printf("%d\n", x);
11 return 0;
12 }
$cat b.c
1 #include <stdio.h>
2
8