Typecasting NULL to far FULL.
D Venkatrangan
venkat at matrix.UUCP
Wed Aug 22 01:38:23 AEST 1990
Greetings, programmers.
I have run into what appears to be a minor problem, but in reality is turning
into a nightmare...
I am writing a library containing interface routines into a driver. These
interface routines are compiled into small, medium and large model libraries.
Since the driver code has its own data segment, these interface routines
convert a model-dependent pointer of the linked program into a far pointer
and then call the driver.
The specific problem is with pointers that are NULL. If I have
char *p;
char far *farp;
and if p is NULL, the following assignment
farp = (char far *)p;
produces a farp with FP_SEG(farp) == current DS and FP_OFF(farp) == 0.
Instead, I want FP_SEG(farp) == 0 and FP_OFF(farp) == 0, because the driver
checks for a (long)0 for NULL pointer and a DS:0 will not be considered to be
NULL by the driver.
Of course, the following assignement produces the correct result.
farp = p ? (char far *)p : (char far *)0L;
But since this is being done many times over, I am interested in a simpler
solution that will avoid the code overhead.
I am using Microsoft C 5.1
Thanks.
More information about the Comp.lang.c
mailing list