#define 设计的精巧

#include <stdio.h>
#include <string.h>

typedef unsigned char lu_byte;

#define CommonHeader    struct GCObject *next; lu_byte tt; lu_byte marked
#define CommonHeader1    {struct GCObject *next; lu_byte tt; lu_byte marked}GCObject1

/* Common type for all collectable objects */
typedef struct GCObject {
    CommonHeader;
} GCObject;

typedef struct GCObject1 CommonHeader1;

#define M(A)    A.marked

#define P(A)    printf("颜值:%d\n",A.marked)

int main() {
    GCObject allgc;
    memset(&allgc,0,sizeof(struct GCObject));
    allgc.marked = 0xF7; //247
    printf("颜值:%d\n",allgc.marked);
    printf("颜值:%d\n",M(allgc));
    //L = G(L)->mainthread;
    printf("------\n");
    P(allgc);

    printf("*******\n");
    GCObject1 allgc1;
    memset(&allgc1,0,sizeof(struct GCObject1));
    allgc1.marked = 0xF8; //248
    P(allgc1);
    return 0;
}

  

 结果

颜值:247
颜值:247
------
颜值:247
*******
颜值:248

  

上一篇:若想学 HTML,应从何入手?


下一篇:在线网站 blog-react 项目的文档说明