This is the mail archive of the gdb@sourceware.org mailing list for the GDB 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]

print/x on references


Currently, there is a slight discrepancy in the behavior of formatted print
commands.  Stop the program below in f.  At that point, we see the
following behavior:

    (gdb) p x
    $4 = (Glorp &) @0x8049850: {x = 1, y = 2}
    (gdb) p/x x
    $5 = 0x8049850

Is there any particular reason these two cases shouldn't have the same
behavior?  It seems that printcmd.c:print_formatted is conflating the
cases of C++ pointers and C++ references, and I don't see the justification
for doing so.  True, it's easy enough to kludge around:

    (gdb) p/x *&x

But it is slightly annoying to have to do this.  Admittedly, I'm speaking
more from the Ada camp, where the equivalent kludge is more verbose (and
from the user's point of view, less motivated).

Still, would anyone object if this behavior were to change?

P. Hilfinger

------------------------------------------------------------


#include <iostream>

using namespace std;

struct Glorp {
  int x, y;
};

Glorp z = { 1, 2 };

void f (Glorp& x) {
  cout << x.x << ", " << x.y << endl;
}

main () {
  f(z);
}


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