Back to home page

DOS ain't dead

Forum index page

Log in | Register

Back to the forum
Board view  Mix view

trip report: Tiny C Compiler 0.9.27 (Miscellaneous)

posted by bencollver Homepage, 11.02.2026, 00:44

I was chugging along replacing TCC's MSVCRT.DLL dependency with Watcom's libc. I got the compiler to self-host. That was fun!

Then i compiled mawk and the floating point math gave bad results. I traced it to parse_number() in tccpp.c:

            } else {
                tok = TOK_CDOUBLE;
                tokc.d = strtod(token_buf, NULL);
            }


I can import strtod() from Watcom's mt7s19.dll, but Watcom's stack calling convention isn't strictly cdecl. The arguments pass in fine, but results are returned in AX:DX where TCC expected them in ST0.

From: i386-gen.c

#define REG_FRET TREG_ST0 /* float return register */

From cguide.pdf:

10.5.2 Returning Values in 80x87-based Applications

When using the stack-based calling conventions with "fpi" or "fpi87", floating-point values are returned in registers. Single precision values are returned in EAX, and double precision values are returned in EDX:EAX


I tried to change TCC to use Watcom's calling convention, but i didn't get it right.

If i read the documentation correctly, it could be easy to write a wrapper DLL. With Watcom's -ecc option, the following wrapper function should automagically translate between cdecl and Watcom's calling convention.

double wtfmath_strtod(const char *s, char **r) {
    return strtod(s, r);
}


That's all i have brain juice for today.

 

Complete thread:

Back to the forum
Board view  Mix view
23231 Postings in 2189 Threads, 405 registered users (0 online)
DOS ain't dead | Admin contact
RSS Feed
powered by my little forum