Eug*_*ffe 2 c gdb pointers double-pointer
在使用 GDB 进行调试时,我注意到一些非常奇怪的事情。即, . 运算符在打印语句中使用时,可以像 -> 运算符一样取消引用单个甚至双指针以获取结构的字段。
这是一个简单的例子:
#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);
}
Run Code Online (Sandbox Code Playgroud)
这是 GDB 在暂停时打印的时间printf:
怎么可能。运算符(在 GDB 打印语句中)取消引用这样的指针??
谢谢!