Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <string.h>
- typedef struct game {
- int enemy_count;
- int bullet_count;
- } game_t;
- typedef game_t* game_p;
- void main() {
- game_t stack_game = {
- .enemy_count = 10,
- .bullet_count = 0
- };
- game_p heap_game = malloc(sizeof(game_t));
- if (NULL == heap_game) {
- // actually should handle the error, display a message and free bound resources before aborting
- abort();
- }
- heap_game->enemy_count = 10;
- heap_game->bullet_count = 0;
- // do stuff
- free(heap_game);
- }
Advertisement
Add Comment
Please, Sign In to add comment