gcc - Compiling c with -fomit-frame-pointer -mrtd creates segfault on free function pointer -


this c code crash segmentation fault if compile gcc using -fomit-frame-pointer , -mrtd.

is code wrong in way? other function pointers works expected, not when free-function being passed? warning when compiling, dont understand why or should fix. (i dont code in c, error comes 3d part library use)

i need rtd/stdcall because im on windows , need call library python ctypes, , -fomit-frame-pointer included default when compiling gcc -o1. (gcc version 4.6.1 tdm/mingw32) feels bit strange default optimization option cause trouble?

c-code:

#include <stdlib.h>  // void free ( void * ptr ); void test(void* o, void (*freefunc)(void*)) {     freefunc(o); }  int main() {     int *p = (int *)calloc(1, sizeof(int));     test(p, free); } 

compiled with:

gcc -fomit-frame-pointer -mrtd -c fx.c gcc -fomit-frame-pointer -mrtd fx.o -o fx.exe 

compile warning:

fx.c: in function 'main': fx.c:11:5: warning: passing argument 2 of 'test' incompatible pointer type[enabled default] fx.c:5:6: note: expected 'void (*)(void *)' argument of type 'void (*)(void *)' 

from gcc manual page -mrtd:

warning: calling convention incompatible 1 used on unix, cannot use if need call libraries compiled unix compiler. 

the warning kind of bizarre, believe it's trying tell you're passing pointer function uses incompatible calling convention. imagine free in libc such function; i'm surprised calling calloc works @ all. (or perhaps isn't, , you're seeing delayed failure!)


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -