gcc does not understand signal handlers:
Code:
#include <signal.h>
#include <stdio.h>
int signalfired;
void sighandler(int s)
{
signalfired = 1;
}
int main()
{
int i = 0;
signal(SIGABRT, sighandler);
while(!signalfired)
{
i++;
if ((i & 15) == 0)
printf("%d\n", i);
}
printf("Signal caught\n");
return 0;
}
generates:
Code:
movl $_sighandler, %edx
xorl %ebx, %ebx
movl %edx, 4(%esp)
call _signal
L10:
movl _signalfired, %eax
L9:
testl %eax, %eax
jne L8
incl %ebx
testb $15, %bl
jne L9
movl %ebx, 4(%esp)
movl $LC0, (%esp)
call _printf
jmp L10
It jumps back to L10 to re-read the signalfired variable only when we call printf. Taking out the printf in the above C code gets this:
Code:
call _signal
movl _signalfired, %eax
.p2align 4,,15
L8:
testl %eax, %eax
je L8
So, the entire loop is just checking the register eax, which is not updated in the loop itself!
Edit: Note that in the beginning of this [or the other closely related] thread there is a mention of "sig_atomic_t", which is the type you SHOULD USE for communication between signal handlers and general code - although I can't make my gcc-mingw work with that either.
--
Mats