Efficient coding considered harmful?

Walter Bright bright at Data-IO.COM
Tue Nov 1 05:30:47 AEST 1988


In article <7421 at ihlpl.ATT.COM> knudsen at ihlpl.ATT.COM (Knudsen) writes:
>In article <8775 at smoke.BRL.MIL>, gwyn at smoke.BRL.MIL (Doug Gwyn ) writes:
>> (But don't write something like
>> 	for (p = &a[j]; --p >= a; )
>> which is nonportable.)
>Why not portable?

If a was created by a call to malloc, and (sizeof(a[0])>2), then on the 8086
in large memory model, p can NEVER be less than a! The trouble results from
malloc creating a segment for a. Decrementing p past a causes a segment
wrap, exactly like decrementing an unsigned variable past 0.

This behavior is allowed for by ANSI C, and is the most reasonable way
of doing things on the 8086.



More information about the Comp.lang.c mailing list