RT-Thread内核-宏 RT_LIST_OBJECT_INIT

1、定义

#define RT_LIST_OBJECT_INIT(object) { &(object), &(object) }

2、作用

RT_LIST_OBJECT_INIT 用于初始化一个双向链表,使双向链表的前一个节点和后一个节点的指针均指向自己。

3、示例程序

#include 

/**
 * @brief initialize a list object
 */
#define RT_LIST_OBJECT_INIT(object) { &(object), &(object) }

/**
 * Double List structure
 */
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. */

static rt_list_t list_node = RT_LIST_OBJECT_INIT(list_node);
static rt_list_t no_init;

 
int main(int argc, char *argv[])
{
    printf("list_node address = %p\r\n",&list_node);
    printf("next address = %p\r\n",list_node.next);
    printf("prev address = %p\r\n",list_node.prev);

    printf("\r\n");
    printf("no_init address = %p\r\n",&no_init);
    printf("next address = %p\r\n",no_init.next);
    printf("prev address = %p\r\n",no_init.prev);

    while (1);
}
/*
list_node address = 0000000000403010
next address = 0000000000403010
prev address = 0000000000403010

no_init address = 0000000000407030
next address = 0000000000000000
prev address = 0000000000000000
*/

 

你可能感兴趣的:(RTOS)