#include <stdio.h>
#include <stdlib.h>
struct A{
int a;
char *p;
};
struct B{
int b;
char *p;
};
#define TYPE(type) \
struct { \
struct type *content; \
}
#define MY(type) \
struct type
int main(){
TYPE(A) x;
x.content = (struct A *)malloc(sizeof(struct A));
TYPE(B) y;
y.content = (struct B *)malloc(sizeof(struct B));
x.content->a = 1;
y.content->b = 2;
MY(A) a;
MY(B) b;
a.a = 10;
b.b = 11;
printf("%d %d %d %d\n", x.content->a, y.content->b, a.a, b.b);
return 0;
}
用define封装结构体简化代码
最新推荐文章于 2023-09-23 17:34:41 发布