//调试环境 VC6.0
#include <stdio.h>
struct rt_list_node
{
struct rt_list_node * next; // point to next node.
struct rt_list_node * prev; // point to prev node.
};
typedef struct rt_list_node rt_list_t; // Type for lists.
struct rt_object_information
{
unsigned char type; // object class type.
rt_list_t object_list; // object list.
unsigned char object_size; // object size.
};
#define _OBJ_CONTAINER_LIST_INIT(c) /
{&(rt_object_container[c].object_list), &(rt_object_container[c].object_list)}
struct rt_object_information rt_object_container[3] =
{
{0, _OBJ_CONTAINER_LIST_INIT(0), 20},
{1, _OBJ_CONTAINER_LIST_INIT(1), 20},
{2, _OBJ_CONTAINER_LIST_INIT(2), 20},
};
struct rt_list_node test1;
struct rt_list_node test2;
void main(void)
{
volatile unsigned int t1;
//rt_list_t * volatile pt1;
rt_object_container[0].type=0x73;
rt_object_container[0].object_size=0x22;
test1.next=(struct rt_list_node *)0x1234;
test1.prev=(struct rt_list_node *)0x5678;
rt_object_container[0].object_list.next=&test1;
rt_object_container[0].object_list.prev=&test2;
t1=(unsigned int) &rt_object_container[0];
printf("pt0= %x /n/n", t1);
t1=(unsigned int)&rt_object_container[0].object_list.next;
printf("pt1= %x /n/n", t1);
t1=(unsigned int)&rt_object_container[0].object_list.prev;
printf("pt2= %x /n/n", t1);
t1= (unsigned int) rt_object_container[0].object_list.next;
printf("pt3= %x /n/n", t1);
t1= (unsigned int)rt_object_container[0].object_list.prev;
printf("pt4= %x /n/n", t1);
t1= (unsigned int)rt_object_container[0].object_list.next -> prev;
printf("pt5= %x /n/n", t1);
t1= (unsigned int)&rt_object_container[0].object_list.next -> prev;
printf("pt55= %x /n/n", t1);
t1= (unsigned int)rt_object_container[0].object_list.next->next;
printf("pt6= %x /n/n", t1);
t1= (unsigned int)&rt_object_container[0].object_list.next->next;
printf("pt66= %x /n/n", t1);
t1= (unsigned int)&rt_object_container[0].object_list.next->next->next;
printf("pt666= %x /n/n", t1);
t1= (unsigned int)&rt_object_container[0].object_list.next->next->prev;
printf("pt6666= %x /n/n", t1);
t1= (unsigned int)rt_object_container[0].object_list.next->next->prev;
printf("pt66666= %x /n/n", t1);
}
//特别是提示出错信息0X1238内存不能读。把0x1238作为了一个地址,此地址是受操作系统保护的。
//仔细理解源码中每行、每字符的意义,可以比较好的理解指针、地址、结构体、结构体指针之间的关系。
本文通过一个具体的C语言实例,展示了如何定义和使用结构体与结构体指针,包括初始化、成员访问等操作,并解释了指针与地址的相关概念。

被折叠的 条评论
为什么被折叠?



