1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | #include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>
// NAÏVE WAY - do not do it like this
//
// Wastes lots of space, and we don't know what kind of data a given
// node contains.
// Use typedef syntax
typedef struct {
int as_int;
char* as_string;
struct Node* as_list;
enum NodeType { NODE_INT, NODE_STRING, NODE_LIST } type; // best
} Element;
// Type is now known as «Element» instead of «struct Element»
typedef struct _Node {
struct _Node* next;
Element value;
} Node;
// Type is now known as «Node» instead of «struct Node»
/* vim: set tabstop=4 shiftwidth=4 fileencoding=utf-8 noexpandtab: */
|
© Copyright 2020 Alexander J. Quinn This content is protected and may not be shared, uploaded, or distributed.