Article View: alt.msdos.programmer
Article #233Re: Turbo C far pointers
From: Bruce Becker
Date: Sun, 29 Oct 1989 01:42
Date: Sun, 29 Oct 1989 01:42
50 lines
1860 bytes
1860 bytes
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". The way you have it the
contents of of *(ptr+i)" contains an int
value which is coerced back to float
in the printf statement.
| for(i=0;i<10;i++)
| printf(" %f", (float) *(ptr+i) ) ; /* is yielding 3.00000 */
Should be printf(" %f", *((float *)(ptr+i)) ) ; /* is yielding 3.1415927 */
|}
|
|Can someone please help me understand what is going on?
|Thanks.
You need to ensure that either by default
or by explicit declaration that
sizeof(far) == sizeof(float); is there a
"far long" type? Better yet, a "far float"?
I didn't actually try this so if your compiler
barfs on "*((float *)ptr)" where "ptr" is a
"far *" declaration, well... you could try
"far float * ptr;", etc...
Cheers,
--
.::. Bruce Becker Toronto, Ont.
w \@@/ Internet: bdb@becker.UUCP, bruce@gpu.utcs.toronto.edu
`/c/-e BitNet: BECKER@HUMBER.BITNET
_/ \_ In the future the term "wife" will have no gender significance
Technical Details
Message-ID:
<990@becker.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!censor!becker!bdbReferences:
<565@titan.tsd.arlut.utexas.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!censor!becker!bdb From: bdb@becker.UUCP (Bruce Becker) Newsgroups: alt.msdos.programmer,comp.sys.ibm.pc Subject: Re: Turbo C far pointers Keywords: float values Message-ID: <990@becker.UUCP> Date: 29 Oct 89 01:42:07 GMT References: <565@titan.tsd.arlut.utexas.edu> Reply-To: bdb@becker.UUCP (Bruce Becker) Organization: G. T. S., Toronto, Ontario Lines: 50