Skip to content

Instantly share code, notes, and snippets.

@Sebbyastian
Created March 28, 2016 23:42
Show Gist options
  • Save Sebbyastian/7f08c422dc5e45876244 to your computer and use it in GitHub Desktop.
Save Sebbyastian/7f08c422dc5e45876244 to your computer and use it in GitHub Desktop.
Opaque type example
#include "living_being.h"
struct living_being {
int meaning;
};
#include <stdlib.h>
void give_birth(living_being **toilet) {
*toilet = malloc(sizeof **toilet);
}
void install_meaning_of_life(living_being **subject) {
(*subject)->meaning = 42;
}
void kill_tragically(living_being **organ_donor) {
free(*organ_donor);
*organ_donor = NULL;
}
#ifndef INCLUDED_LIVING_BEING
#define INCLUDED_LIVING_BEING
struct living_being;
typedef struct living_being living_being;
void give_birth(struct living_being **);
void install_meaning_of_life(struct living_being **);
void kill_tragically(struct living_being **);
#endif
#include <stdlib.h>
#include "living_being.h"
int main(void) {
living_being *Chris_Pirillo = NULL;
give_birth(&Chris_Pirillo);
install_meaning_of_life(&Chris_Pirillo);
kill_tragically(&Chris_Pirillo);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment