30 lines
458 B
C
30 lines
458 B
C
#include <stdio.h>
|
|
#include "handle.h"
|
|
|
|
struct Meaning {
|
|
int a;
|
|
int b;
|
|
};
|
|
|
|
handle(Meaning) {
|
|
if(state == HANDLE_CREAT) {
|
|
// Constructor
|
|
self->a = *(int*) data;
|
|
self->b = 2;
|
|
} else {
|
|
// Destructor
|
|
printf("%d\n", self->a + self->b);
|
|
}
|
|
}
|
|
|
|
// Now you can use a handle in your local scopes
|
|
// Should print 42:
|
|
int main() {
|
|
int initializer = 40;
|
|
creat(Meaning, d, &initializer);
|
|
initializer = 20;
|
|
creat(Meaning, d2, &initializer);
|
|
|
|
return 0;
|
|
}
|