Skip to content

Instantly share code, notes, and snippets.

@raypulver
Created December 8, 2017 22:41
Show Gist options
  • Save raypulver/056818790171cdb3fa59b32394156027 to your computer and use it in GitHub Desktop.
Save raypulver/056818790171cdb3fa59b32394156027 to your computer and use it in GitHub Desktop.
cyclic struct definitions
typedef struct _ast_binop_t {
ast_node_t *left;
ast_node_t *right;
} ast_binop_t;
typedef union _ast_data_t {
int integer;
ast_node_t node;
char *id;
ast_binop_t binop;
} ast_data_t;
typedef struct _ast_node_t {
int type;
ast_data_t data;
} ast_node_t;
@hmcq6
Copy link

hmcq6 commented Dec 8, 2017

Does this work? Nope

typedef struct _ast_binop_t {
  struct ast_node_t *left;
  struct ast_node_t *right;
} ast_binop_t;

typedef union _ast_data_t {
  int integer;
  struct ast_node_t node;
  char *id;
  struct ast_binop_t binop;
} ast_data_t;

typedef struct _ast_node_t {
  int type;
  struct ast_data_t data;
} ast_node_t;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment