Skip to content

Instantly share code, notes, and snippets.

@jonbro
Last active August 29, 2015 14:19
Show Gist options
  • Select an option

  • Save jonbro/e87600f765cfde2c62dc to your computer and use it in GitHub Desktop.

Select an option

Save jonbro/e87600f765cfde2c62dc to your computer and use it in GitHub Desktop.
// types
typedef struct lipsynth_Module lipsynth_Module;
struct lipsynth_Module {
// blah blah a bunch of values and pointers and stuff
// the only one that I am getting confused about
int module_registration;
};
// the declaration of the thing (in a header)
extern lipsynth_Module lipsynth_module_sine_proto;
// setting the value of the thing
lipsynth_Module lipsynth_module_sine_proto = {
.lipsynth_Module_init = lipsynth_module_sine_init,
.lipsynth_Module_update = lipsynth_module_sine_update,
.lipsynth_Module_register_parameters = lipsynth_Module_sine_register_parameters
};
// here is where stuff goes wrong
void init_system(){
// non-functional (seems to copy)
lipsynth_Module* modulePrototypes [] = {
lipsynth_module_mixer_proto,
lipsynth_module_sine_proto,
lipsynth_module_sampler_proto
};
for(int i = 0;i<3;i++){
lipsynth_core_register_module(ctx, &modulePrototypes[i]);
}
// functional, obv these wouldn't both be in the code at the same time
lipsynth_Module* modulePrototypes [] = {
&lipsynth_module_mixer_proto,
&lipsynth_module_sine_proto,
&lipsynth_module_sampler_proto
};
for(int i = 0;i<3;i++){
lipsynth_core_register_module(ctx, modulePrototypes[i]);
}
create_instance_of_thing(lipsynth_module_sine_proto);
}
int lipsynth_core_register_module(lipsynth_context *ctx, lipsynth_Module *module_type){
module_type->module_registration_number = ctx->registered_module_count;
ctx->registered_module_count++;
return 1;
}
void create_instance_of_thing(Lipsynth_Module proto){
proto.module_registration_number <- NOT THE CORRECT VALUE!
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment