/* This small program causes a libgc error when compiled and run in Cygwin: $ gcc gcerror.c -lgc -o x.exe $ ./x.exe 42 GC Warning: Thread stack pointer 0x22aa98 out of range, pushing everything */ #include #include void *dummy; void f (void (*x)()) { x(); } int main () { int i; void g () { printf("%i\n", i); } i = 42; f(g); dummy = GC_MALLOC(10); return 0; } /* The presence of a function call that is passed a pointer to a Gnu C nested function with a closure seems to cause the problem: * There is no error if: - i is global; - i is not used in g; - g is called normally (not passed to f); - f is not called; - GC_MALLOC is not called; - GC_MALLOC is replaced with malloc. * There is still an error if: - f does not call g; - GC_MALLOC is called before f. The bug also causes memory corruption when it occurs larger programs. Programs with libgc and this construct always work correctly in Debian Stable. */