Address arithmetic on the '286 (was: Is &a[NTHINGS] legal)

Chip Salzenberg chip at ateng.UUCP
Wed May 18 05:59:54 AEST 1988


Note:  this article is specific to the Intel 8086 and '286.

In article <4554 at ico.ISC.COM> rcd at ico.ISC.COM (Dick Dunn) writes:
>[on the '286]
>...you might like to declare, say
>	char stuff[65536];
>
>[The compiler] can form an address &stuff[65536] which is usable for
>comparison--and address arithmetic--even though it's not a valid address
>(nor even a valid segment, for that matter).
>
>However--here, 286 compiler folks take note--it does require treating
>pointer comparison as a 32-bit operation for <, <=, >, >= (not just == and
>!=).

Your idea would work, but only if all pointer _arithmetic_ were done in
32 bits as well.  Take for example:

	static  char    foo[65536];
	main()
	{
		char *p = &foo[65536];
		p[-1] = 'a';
	}

However -- doing all pointer arithmetic in 32 bits would slow down _all_
pointer operations, even though the vast majority of them do not need it.
I'd rather just declare individual arrays as "huge" and leave 16-bit
pointer arithmetic as the default.

I know it's not fully conformant to dpANS.  Too bad.

I'd rather lose conformance than performance.
-- 
Chip Salzenberg                "chip at ateng.UU.NET" or "codas!ateng!chip"
A T Engineering                My employer may or may not agree with me.
  "I must create a system or be enslaved by another man's." -- Blake



More information about the Comp.lang.c mailing list