c_cpp 使用宏来连接堆对象
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp 使用宏来连接堆对象相关的知识,希望对你有一定的参考价值。
#include "stdio.h"
#include "stdlib.h"
#define XenObject_HANDLE unsigned char type; \
struct XenObject * next; \
struct XenObject * prev;
struct XenObject
{
XenObject_HANDLE
};
typedef struct XenObject XenObject;
#define XenObject_GETTYPE(xo) xo->type
#define XenObject_SETTYPE(xo, t) xo->type = t
#define XenObject_SAMETYPE(xo1, xo2) xo1->type == xo2->type
#define XenObject_CASTOBJ(xo) (XenObject*)xo
#define XenObject_CONNECT_NEXT(xo1, xo2) do { \
xo1->next = xo2; \
xo2->prev = xo1; } while(0)
#define XenObject_CONNECT_PREV(xo1, xo2) do { \
xo1->prev = xo2; \
xo2->next = xo1; } while(0)
#define XenObject_APPEND(xo1, xo2) do { \
while(xo1->next != NULL) \
{ \
xo1 = xo1->next; \
} \
xo1->next = xo2; \
xo2->prev = xo1; \
}while(0)
int main(void) {
XenObject* one = malloc(sizeof(XenObject));
XenObject* two = malloc(sizeof(XenObject));
XenObject_SETTYPE(two, 3);
XenObject_CONNECT_NEXT(one, two);
XenObject* three = malloc(sizeof(XenObject));
XenObject_SETTYPE(three, 7);
XenObject_APPEND(one, three);
printf("Hello World\n");
printf("two's type is %d", XenObject_GETTYPE(one->next));
return 0;
}
以上是关于c_cpp 使用宏来连接堆对象的主要内容,如果未能解决你的问题,请参考以下文章
c_cpp c宏来确定os
c_cpp 数组是否代表堆
c_cpp 堆
c_cpp 堆
c_cpp 堆。空手。
c_cpp 堆排序