struct { int x; } s = { 42 }; int main (void) { return s.x; } OK: (gdb) p s.x $2 = 42 But this is wrong: (gdb) p s->x $3 = 42 GCC prints: .c:6: error: invalid type argument of ‘->’ (have ‘struct <anonymous>’) GNU gdb (GDB) 7.2.50.20100728-cvs
GDB also permits . on a pointer to struct, so this could be considered convenience. Apparently . and -> are basically treated the same.
From the manual: @item .@r{, }-> Structure member, and pointer-to-structure member. For convenience, @value{GDBN} regards the two as equivalent, choosing whether to dereference a pointer based on the stored type information. Defined on @code{struct} and @code{union} data.
I did not know, OK, thanks. It is true GDB also intentionally lookups `static' objects from other files which is also not exactly following the C language rules. Which I may disagree with but this is all I can do.
FWIW -- I think there are some minor differences between the two. And, we may introduce a few more, since it isn't clear that, e.g., "foo.x" should use an overloaded operator->