0

That one surprised me, when doing for auto complete for a breakpoint it appeared two options to the same method.

test::TestFoo::SendFoo(short)
test::TestFoo::SendFoo(short)::fooID

On cpp:

bool TestFoo::SendFoo( short x )
{
   ...
   static unsigned int fooID = 0;

Why gdb differs? what's the benefit of using one or another?

Question tagged as C++ to avoid any missunderstanding from C static.

gdb --version
GNU gdb (GDB) Red Hat Enterprise Linux (7.2-56.el6)
...
4

1 回答 1

2

SendFoo::fooID and SendFoo are two different kinds of symbols, and I can imagine there will be a difference in the two breakpoints gdb offers you - although I am not very familiar with it:

The line where fooID is defined/initialized will be only hit once in the whole program, so a breakpoint in that line should be hit only once as well. A function level breakpoint should be hit every time the function gets called, so there is a major difference.

AFAIK the function scope static means the same for both C and C++ - a variable that is shared between all calls of that function and initialized the first time the function gets called.

于 2012-12-07T13:13:37.027 回答