When debugging with GDB, I noticed something very strange. Namely, the . operator, when used in a print statement, can act just like the -> operator dereferencing a single or even double pointer to get to a field of a struct.
Here's a simple example:
#include <stdio.h>
typedef struct node {
struct node *next;
int data;
} Node;
int main()
{
Node head, *head_p, **head_pp;
head.next = 0UL;
head.data = 42;
head_p = &head;
head_pp = &head_p;
// **GDB PAUSED HERE**
printf("head.data: %d\n", head.data);
// These won't compile because the . operator is misused
//
// printf("head_p.data: %d\n", head_p.data);
// printf("head_pp.data: %d\n", head_pp.data);
}
Here's when GDB prints when paused at the printf:
How can the . operator (in a GDB print statement) dereference a pointer like that??
Thanks!
