Re: ver 4.0 c_func problem on WIN98 Here Is proof of the problem !
- Posted by mattlewis (admin) Apr 24, 2009
- 1177 views
Now the question is, is the bug Watcom's fault or not? In other words, should the compiler be saving and restoring registers for us or is your machine code suppose to do that? This is beyond the internals of Euphoria, but entering the realm of the internals of Watcom C, the realm of the Watcom developer team.
After thinking about this, I believe that it must be the called function's responsibility. If it were the calling function's responsibility, then it would have to know which registers were modified. But this clearly cannot work (just imagine how it would work with dynamic linking, or indeed any function pointer whose contents cannot be known at compile time), so it would always have to save all registers. Indeed, looking at the top and bottom of the emitted assembly code for call_c, we can see that it saves the registers that it uses:
0000 call_c_: 0000 51 push ecx 0001 56 push esi 0002 57 push edi 0003 55 push ebp ... 047B 5D pop ebp 047C 5F pop edi 047D 5E pop esi 047E 59 pop ecx 047F C3 retI think that this bug in Bernie's code was previously hidden only because the compiler wasn't counting on the esi register being changed at that point in the code.
Matt