[comp.sys.ibm.pc] TURBO C Bug - huge arrays

tjr@ihnet.ATT.COM (Tom Roberts) (08/12/87)

I have just encountered another TURBO C Bug (groan!).

Consider:
	struct x {
		int id;
		char space[126];
	} huge *x;	/* sizeof(struct x) = 128 */
	int n;
	n = 520;
	x = (struct x huge *)farmalloc((long)n*sizeof(struct x));
Now x[0] thru x[511] are OK, but x[512] is the same as x[0].

If I do this:
	struct x huge *p;
	p = x;
	for(n=0; n<512; ++n)
		++p;
Now, *p is OK (i.e. not x[0]).

This doesn't work either:
	n = 512;
x[(long)n] is still the same as x[0].


Clearly, when handling arrays, the compiler is simply adding to the
offset of the huge pointer, and is not properly adjusting the segment (or
not using long arithmetic to multiply n and sizeof(struct x)).
This problem occurs in both the S and the L memory models (and probably
all of the others).

So, is there any way to use an array of structures that totals more than
64kb, without doing all of the groty arithmetic myself?

Tom Roberts
ihnet!tjr