Search code examples
cwatcom

How to make C function compiled by OpenWatcom return a double in ST(0)?


The C function

double retfp(void) { return 42; }

, when compiled with OpenWatcom C compiler for Linux i386:

owcc -blinux -fno-stack-check -fsigned-char -march=i386 -Os -W -Wall -Wextra -Werror -mregparm=0 -c -o retfp.owcc.obj retfp.c

has code which returns the double in EDX:EAX. However, I want to get it in ST(0) instead, like how GCC does it. Is thiss possible with OpenWatcom, maybe via a command-line flag?


Solution

  • You should specify calling convention which returns floating point values in ST(0), for example cdecl:

    double __cdecl retfp(void) {  return 42; }
    

    Dissassembler output:

    Segment: _TEXT BYTE USE32 00000007 bytes
    0000                            _retfp:
    0000  DD 05 00 00 00 00                 fld             qword ptr L$1
    0006  C3                                ret
    ...
    Segment: CONST DWORD USE32 00000008 bytes
    0000                            L$1:
    0000  00 00 00 00 00 00 45 40                         ......E@
    

    Also you can specify default calling convention to owcc with -mabi flag.