I'm created an opaque type and I have two options for its management.
The first looks like this:
type_t *a = type_init();
int err;
err = type_do(a, "foo", "bar", FLAGBIT1|FLAGBIT2, NULL);
if (!err) {
type_print_result(a);
...
}
type_free(a);
The second is:
type_t *a;
int err;
err = type_do(&a, "foo", "bar", FLAGBIT1|FLAGBIT2, NULL);
if (!err) {
type_print_result(a);
...
}
type_free(a);
type_do
is the function that calculates the results we could work on. As you may underastand in the second case the initialization happens within type_do
, that's why I have to pass the address of a
. It is absolutely necessary to call type_do
before doing anything else with type_t
. Is there any reason to have a separate init function?