On Mon, 21 Sep 2020, John Cowan wrote:
On Mon, Sep 21, 2020 at 1:55 AM Steve Nickolas
<usotsuki(a)buric.co> wrote:
I've never written anything that uses
varargs, so I've never run into
that. But I've actually done quite a bit of work with an environment
where this isn't true: MS-DOS using the large or huge model. In this
environment, sizeof(int)=2, and sizeof(void*) is 4. Of course, it's not
conformant to pass an int variable as an argument where a pointer variable
is expected.
If the compiler was ISO-conformant (which it almost certainly was not),
that would not matter. 0 in int context would be a 2-byte int with all
bits zero, and 0 in pointer context would be a 4-byte null pointer,
probably with all bits zero.
The compiler I used at least tried to be C89. (Borland Turbo C++ 1.01)
C doesn't require that the address represented by
the null pointer (whether
or not it is all-bits-zero) is inaccessible, merely that there is no C
object or function there. A simple shim of the appropriate size (1, 2, 4,
8 bytes depending on the CPU's alignment rules) will suffice.
Which was nice with the tiny model: a .COM file organized at near 0x0100,
and iirc, there was guaranteed to be 0xCD 0x20 at 0x0000. (The 8086 "INT
20H" instruction. I just checked in DOSEMU with PC DOS 7, and that is
exactly what shows up there.)
"ANSI C" doesn't mean a lot though when 95% of the code I run across uses
extensions. I still have not successfully kitbashed the Bourne shell onto
native DOS, OS/2 or Windows without an emulation layer - in any form. Did
come *pretty* close with the Forsyth shell but I couldn't work around the
lack of fork() (OS/2 does have a near-exact counterpart for pipe(), but
it's not exposed by the pipe() call for some reason.) I like my Unix
shells even on Microsoft OSes...call me crazy. ;)
-uso.