Skip to content

Instantly share code, notes, and snippets.

@munen
Created October 31, 2011 10:56
Show Gist options
  • Save munen/1327280 to your computer and use it in GitHub Desktop.
Save munen/1327280 to your computer and use it in GitHub Desktop.
struct {
int a;
union {
int b;
float c;
};
int d;
} foo;
@tpo
Copy link

tpo commented Oct 31, 2011

A possible use as "class interface":

struct state_machine_t {
        int some_state;
        // etc.
};

struct stateful_object_t {
        struct state_machine_t;
};

void transition( struct stateful_object_t* o) {
        o.some_state = 77;
        // etc.
}

// same interface as stateful_object_t !
//
struct automat_t {
        struct state_machine_t;
        char* name;
        // etc.
};

main() {
        struct automat_t automat;
        transition((struct stateful_object_t*)&automat);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment