用define封装结构体简化代码

来源:互联网 发布:能看被禁动漫的软件 编辑:程序博客网 时间:2024/04/30 06:46
#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;}

0 0