This is the mail archive of the archer@sourceware.org mailing list for the Archer project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [python] more tests and documentation


On Thu, Oct 23, 2008 at 1:14 PM, Tom Tromey <tromey@redhat.com> wrote:
> Tom> On second thought, I understand stripping const (and volatile and
> Tom> restrict).
>
> What do you think of this?

Looks good.

You are right about references being automatically dereferenced
and pretty-printed. However consider this:

// --cut-- t.cc
#include <string>
#include <vector>

int main()
{
    std::vector<std::string> vs;
    vs.push_back("Hello");
    vs.push_back("World");
    return vs[0].length(); // break here
}
// --cut-- end

Without stripping references (current code), this prints:

(gdb) p vs
$1 = std::vector of length 2, capacity 2
     [0] = 0x603028 "Hello"
     [1] = 0x603078 "World"
(gdb) p vs[0]
$2 = (std::basic_string<char,std::char_traits<char>,std::allocator<char>
> &) @0x603090: 0x603028 "Hello"


But if I do strip reference type, it prints:

(gdb) p vs
$1 = std::vector of length 2, capacity 2
     [0] = 0x603028 "Hello"
     [1] = 0x603078 "World"
(gdb) p vs[0]
$2 = 0x603028 "Hello"


Notice that (from the end user perspective) 'print vs' and 'print
vs[0]' are semantically very close, so it's surprizing that one
prints more "junk" than the other.

Also, in real usage we often have
vector<some-complicated-type-with-20-template-parameters>, so
now 'print vs[0]' results in 20 lines of "junk" followed by the
info that user actually wants.

-- 
Paul Pluzhnikov


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]