Re: ver 4.0 c_func problem on WIN98 Here Is proof of the problem !
- Posted by mattlewis (admin) Apr 24, 2009
- 1170 views
mattlewis said...
We should probably take a look at the generated assembly to see what it's doing.
I added a couple of printf statements:
printf("1: return_type %8x %8x\n", return_type, int_proc_address ); iresult = (*((int (__stdcall *)())int_proc_address))(); printf("2: return_type %8x %8x\n", return_type, int_proc_address );
When calling Bernie's procedure, here's what we get:
1: return_type 2000004 ad7545 2: return_type b01ea8 ad7545
So it's clear that return_type is changing. Looking at the assembly for the printf and the call:
printf("1: return_type %8x %8x\n", return_type, int_proc_address ); 0378 8B 45 E8 mov eax,dword ptr -0x18[ebp] 037B 50 push eax 037C 56 push esi 037D 68 AB 01 00 00 push offset L$58 0382 E8 00 00 00 00 call printf_ iresult = (*((int (__stdcall *)())int_proc_address))(); 0387 83 C4 0C add esp,0x0000000c 038A 8B 5D E8 mov ebx,dword ptr -0x18[ebp] 038D FF 55 E8 call dword ptr -0x18[ebp] printf("2: return_type %8x %8x\n", return_type, int_proc_address ); 0390 53 push ebx 0391 56 push esi 0392 68 C4 01 00 00 push offset L$59 0397 89 C2 mov edx,eax 0399 89 C1 mov ecx,eax 039B E8 00 00 00 00 call printf_It looks like return_type is being stored in esi. I notice that Bernie's code modifies esi. I'm not sure whose responsibility it is to restore esi, but the problem appears to be that Watcom thinks that it's Bernie's job to restore any registers. That also helps explain why, when I took the address of return_type, it started working again
Matt