Segmentation fault with function pointers
Posted: Fri Aug 12, 2011 9:35 am
I've just started playing with creating shared libraries (and libraries in general) and I've come across an issue. In my library I have a function called setInitFunc which takes a function pointer to a function that returns nothing and takes nothing.
void (*initFunc)(void), when I build my test application the program crashes midway through the function. The first line is a debug saying "setInitFunc()", last line says "endInitFunc", the middle line just sets one of my global function pointers to what was passed in. (Relevant code below, if you need more just ask). This is being done in C using Codeblocks on Ubuntu 10.04.
Definition of setInitFunc (in FrozenCore.c)
main.c
void (*initFunc)(void), when I build my test application the program crashes midway through the function. The first line is a debug saying "setInitFunc()", last line says "endInitFunc", the middle line just sets one of my global function pointers to what was passed in. (Relevant code below, if you need more just ask). This is being done in C using Codeblocks on Ubuntu 10.04.
Definition of setInitFunc (in FrozenCore.c)
Code: Select all
void setInitFunc( void (*initFunc)(void) ) {
printf("setInitFunc()\n");
init = initFunc;
printf("endInitFunc\n");
}
Code: Select all
#include "FrozenCore.h"
void init() {
}
void update() {
}
void render(SDL_Surface* screen) {
SDL_Rect rect = (SDL_Rect) {25, 25, 25, 25};
SDL_FillRect(screen, &rect, SDL_MapRGB(screen->format, 255, 255, 0));
}
int main(int argc, char* argv[]) {
setInitFunc(init);
setUpdateFunc(update);
setRenderFunc(render);
startGame(640, 480, 0);
return 0;
}