Created
March 28, 2016 23:42
-
-
Save Sebbyastian/7f08c422dc5e45876244 to your computer and use it in GitHub Desktop.
Opaque type example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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