🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.msdos.programmer
Article #548

Typecasting NULL to far FULL.

#548
From: D Venkatrangan
Date: Tue, 21 Aug 1990 15:38
36 lines
1616 bytes
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.
Technical Details
Message-ID: <164@matrix.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!mailrus!umich!yale!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!sdd.hp.com!decwrl!uunet!matrix!venkat

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!mailrus!umich!yale!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!sdd.hp.com!decwrl!uunet!matrix!venkat
From: venkat@matrix.UUCP (D Venkatrangan)
Newsgroups: alt.msdos.programmer,comp.os.msdos.programmer,comp.lang.c
Subject: Typecasting NULL to far FULL.
Message-ID: <164@matrix.UUCP>
Date: 21 Aug 90 15:38:23 GMT
Distribution: na
Organization: Matrix Computer Systems, Nashua, NH
Lines: 36