Article View: alt.msdos.programmer
Article #242Re: Turbo C far pointers
From: Dion Hollenbeck
Date: Wed, 01 Nov 1989 00:54
Date: Wed, 01 Nov 1989 00:54
45 lines
1709 bytes
1709 bytes
From article <990@becker.UUCP>, by bdb@becker.UUCP (Bruce Becker):
> In article <565@titan.tsd.arlut.utexas.edu> elrond@titan.tsd.arlut.utexas.edu (Brad Hlista) writes:
> |I am having a problem of getting an allocated block of far memory
> |to return float values. Here is how variables are declared and dereferenced:
> |
> |far *ptr;
> |
> |main()
> |{
> |int i;
> |
> | ptr=(float *) farmalloc(100000);
> |
> | f(i=0;i<1000;i++)
> | *(ptr+i)=3.1415927;
>
> Should be: *((float *)(ptr+i)) = 3.1415927;
>
> Otherwise the "far" declaration of "ptr"
> will force a type conversion to the default
> of type "int".
If the pointer is declared to be of type "float far *" then the
statement "ptr + i" says "ptr + sizeof(type of ptr)*i" even
though i is an int. If this does not occur, then the compiler
is broken. The program could be written thusly:
main()
{
float far *ptr;
ptr = (float *) farmalloc(100000);
f(i=0;i<1000;i++)
*(ptr+i)=3.1415927;
}
The key is to declare the pointer to be a far ptr to a type of float
and incrementation and pointer arithmetic will work.
Dion Hollenbeck (619) 455-5590 x2814
Megatek Corporation, 9645 Scranton Road, San Diego, CA 92121
uunet!megatek!hollen or hollen@megatek.uucp
Technical Details
Message-ID:
<792@megatek.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!cs.utexas.edu!tut.cis.ohio-state.edu!ucbvax!hplabs!hp-sdd!megatek!eta!hollenReferences:
<990@becker.UUCP>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!cs.utexas.edu!tut.cis.ohio-state.edu!ucbvax!hplabs!hp-sdd!megatek!eta!hollen From: hollen@eta.megatek.uucp (Dion Hollenbeck) Newsgroups: alt.msdos.programmer,comp.sys.ibm.pc Subject: Re: Turbo C far pointers Message-ID: <792@megatek.UUCP> Date: 1 Nov 89 00:54:21 GMT References: <990@becker.UUCP> Sender: news@megatek.UUCP Lines: 45