Article View: comp.os.msdos.programmer
Article #4722huge-far pointer and Turbo C++ V1
From: Stephen Johnson
Date: Mon, 18 Feb 1991 22:57
Date: Mon, 18 Feb 1991 22:57
75 lines
2004 bytes
2004 bytes
/* The following program should be compiled with:
tcc -mh <prog>.c
This program allocates a very large array of memory
and addresses using the "far" key word. Unfortunately, the
address calculations rap around at 64k. Does anyone know why
this happens? Is this a bug in the Turbo C++ libraries?
I am using Trubo C++ V1.0 on a Dell 310 (386 box)
with 640k of DOS memory and 4 Meg of real memory.
thanks, Stephen Johnson
*/
#include <stdio.h>
#include <alloc.h>
#define ULONG unsigned long
ULONG far *zbuffer = NULL;
void z_buffer_init();
void z_buffer_test();
main()
{
printf("Available memory: %lu\n", farcoreleft());
printf("We will allocate: %lu\n", (ULONG)sizeof(ULONG) *
(long)320 * (long)200);
zbuffer = (ULONG far *)farmalloc((ULONG)sizeof(ULONG) *
(ULONG)320 * (ULONG)200);
z_buffer_init();
z_buffer_test();
}
void
z_buffer_init()
{
ULONG far *zbuf;
long nwords = (long)320 * (long)200;
zbuf = zbuffer;
while (--nwords) {
*zbuf = (ULONG)(((ULONG)1 << (ULONG)24) - (ULONG)512);
zbuf++;
}
}
void
z_buffer_test()
{
long nwords = (long)320 * (long)200;
ULONG far *zbuf;
zbuf = zbuffer;
while (--nwords) {
if (*zbuf > (ULONG)10) {
*zbuf = (ULONG)10;
}
else {
printf("nwords: %lu\n", nwords);
printf("value: %lx\n", *zbuf);
printf("start: %lx\n", (ULONG)zbuffer);
printf("addr: failed at %lx\n", (ULONG)zbuf);
return;
}
zbuf++;
}
}
Technical Details
Message-ID:
<8138@exodus.Eng.Sun.COM>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!cs.utexas.edu!sun-barr!newstop!exodus!deblil.Eng.Sun.COM!stephenjShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!cs.utexas.edu!sun-barr!newstop!exodus!deblil.Eng.Sun.COM!stephenj From: stephenj@deblil.Eng.Sun.COM (Stephen Johnson) Newsgroups: comp.os.msdos.programmer,alt.msdos.programmer,comp.os.msdos.apps Subject: huge-far pointer and Turbo C++ V1 Keywords: huge-far Message-ID: <8138@exodus.Eng.Sun.COM> Date: 18 Feb 91 22:57:38 GMT Sender: news@exodus.Eng.Sun.COM Followup-To: comp.os.msdos.programmer Lines: 75