This is the install_allegro line:
install_allegro(SYSTEM_AUTODETECT, &errno, stabilize_before_exit);
this is the exit function
int stabilize_before_exit (void) { allegro_exit(); return 0; }
Currently this is just getting things set up properly, I haven't actually started anything real yet...
Anyway, the error I'm getting is
invalid conversion from `int (*)()' to `int (*)(void (*)())'
according to Dev-C++, on the install_allegro line. Anyone know what's going on?
Remove the void inside your argument list.
didn't help
You don't have to call allegro_exit manually. What you are trying to do is actually done by allegro automatically
thanks for the tip, but it still didn't help
Have you declared the function before using it in the callback?
the function is the first line in the source file, I've tried it before and after #include <allegro.h>
sorry, I'm not entirely sure what you mean by "before using it in the callback"
#include <allegro.h> int stabilize_before_exit () { allegro_exit(); return 0; } int main(int argc, char* argv[]){ install_allegro(SYSTEM_AUTODETECT, &errno, stabilize_before_exit); return 0; } END_OF_MAIN()
gcc -w -Wall helloworld.c `allegro-config --libs`
I get zero errors or warnings
Uhm....... as far as I know the last argument should point to atexit... that tells allegro what to call to register its own exit callback. Hence the void (*) error, because atexit takes a void*.
[edit]
The `errno_ptr' and `atexit_ptr' parameters should point to the errno variable and atexit function from your libc: these are required because when Allegro is linked as a DLL, it doesn't have direct access to your local libc data. `atexit_ptr' may be NULL, in which case it is your responsibility to call allegro_exit() manually. Example:
install_allegro(SYSTEM_AUTODETECT, &errno, atexit);
Yep. So, if you want your own function called at the end, run atexit(stabilize_before_exit); in your main.
oh I see... sorry I misunderstood that feature. Okay, I got it now.
because atexit takes a void*.
No
#include <stdlib.h>
int atexit(void (*func)(void));
This function places the specified function func on a list of functions to be called when exit is called. These functions are called as if a last-in-first-out queue is used, that is, the last function registered with atexit will be the first function called by exit.
At least 32 functions can be registered this way.
A void * as in avoid function pointer.