What is the point of this series of C typedef / struct / union / enum definitions?

Inside this, the first step in the direction of the interpreter is the boot circuit. I find the following set of definitions for typedef, struct, union, and enum:

typedef enum {FIXNUM} object_type;

typedef struct object {
    object_type type;
    union {
        struct {
            long value;
        } fixnum;
    } data;
} object;

In particular, I'm not sure that I understand the point of the structure inside the union ( struct { long value; } fixnum;) - a structure with only one field to hold one long? Very strange.

But I'm not quite sure that I understand the big point. I think that what happens with the enum definition is that it sets up several possible type values ​​for lexical objects and that objectthis is a way to store them, but maybe someone with more practice in C than I can offer a more detailed explanation.

Thank!

+3
2

: -a-union-inside-a-struct , . , , , .

:

typedef enum {BOOLEAN, FIXNUM} object_type;

typedef struct object {
    object_type type;
    union {
        struct {
            char value;
        } boolean;
        struct {
            long value;
        } fixnum;
    } data;
} object;

object ( ), . , - . , , fixnums, .

, parallelism. v0.6 pair, .

+3

. , .

. - .

, enum , :

typedef enum {FIXNUM,FLOATNUM} object_type;

typedef struct object {
    object_type type;
    union {
        struct { long  value; } fixnum;
        struct { float value; } floatnum;
    } data;
} object;

, , , :

typedef enum {FIXNUM,FLOATNUM,STRING} object_type;

typedef struct object {
    object_type type;
    union {
        struct { long  value;             } fixnum;
        struct { float value;             } floatnum;
        struct { size_t len;  char *data; } string;
    } data;
} object;

, , , , .

+2

Source: https://habr.com/ru/post/1769073/


All Articles