Skip to content

Instantly share code, notes, and snippets.

@zbanks
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zbanks/104906ba778675c42a7f to your computer and use it in GitHub Desktop.
Save zbanks/104906ba778675c42a7f to your computer and use it in GitHub Desktop.
// Common:
struct endpoint {
struct node * node;
pull_fn_pt pull;
//const type_t * type; // Maybe...
//const char * name; // Maybe...
};
// Type 1:
struct node {
block_destroy_fn_pt destroy;
object_t * state;
size_t n_inputs;
struct endpoint ** inputs;
size_t n_outputs;
struct endpoint outputs[];
};
node = malloc(sizeof(struct node) + n_outputs * sizeof(struct endpoint));
node->inputs = malloc(n_inputs * sizeof(struct endpoint *));
node->inputs[i]->node...
node->outputs[o].node...
// Type 2:
struct node {
block_destroy_fn_pt destroy;
object_t * state;
size_t n_inputs;
size_t n_outputs;
union endpoint_or_ptr {
struct endpoint * input;
struct endpoint output;
} endpoints[];
};
node = malloc(sizeof(struct node) + (n_inputs + n_outputs) * sizeof(union endpoint_or_ptr));
node->inputs[i].input->node...
node->outputs[n_inputs + o].output.node...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment