Hi David, thank you for your reply!
Yes. It may not be the best design, but you can call callback
functions directly if you like.
What would be a good design? To make a function that is called by
the callback function and to call it manually when needed? Is this
a better solution? Well, this might not be a topic that fits in a
message and that somebody would like to discuss but… well, I ask.
Well, that depends entirely on your application and how you decide to
design it. It’s just been my experience that using API provided
callback prototypes for other things than they’re really meant for
(ie for some backend to call functions your provide) isn’t a very
good idea. The most obvious reason is that it makes your code harder
to port to other APIs. Another reason is that it gives you more of
that horrible void pointer casting you need to pass custom data to
the callbacks.
timer = SDL_AddTimer( 1000, Switch, );
or as you would declare your callback function:
Uint32 my_timer_func(Uint32 interval, void *param);
I’m sorry but I still cannot understand how to pass the parameters
Do you mean something like this bellow?
int a = 100;
param = &a;
Yeah, that would be a most basic example. ‘a’ could be anything you
can get the address of. Just make sure the data is still there when
the callback function is invoked, and that you get the typecasting
right. In this case you could just
timer = SDL_AddTimer( 1000, Switch, &a);
In your callback, you have to cast the pointer before you can use it,
something like this:
Uint32 my_timer_func(Uint32 interval, void *param)
{
int *my_param = (int *)param;
...
}
Of course, whatever you pass can be written as well, as it’s passed by
reference. Kinda’ natural with structs, but it’s not how you pass an
int argument normally. Might be worth keeping the difference in mind.
timer = SDL_AddTimer( 100, my_timer_func, param );
Sorry for bothering anyone but I’m not much experienced in C
Might be a good idea to get a book on C. It’s a rather picky and
sensitive language, so I’d strongly recommend that you read up on
stuff before trying to make it work through experimentation. Too many
chances of running into something that’s “almost” right…
Unfortunately, the only C book I can think of is also one of the few
I’ve ever seen in swedish - and it’s not a translation. Sorry…
//David Olofson - Programmer, Composer, Open Source Advocate
.- The Return of Audiality! --------------------------------.
| Free/Open Source Audio Engine for use in Games or Studio. |
| RT and off-line synth. Scripting. Sample accurate timing. |
`-----------------------------------> http://audiality.org -’
— http://olofson.net — http://www.reologica.se —On Saturday 10 May 2003 17.56, Billi Bot wrote: