Xref: utzoo comp.sys.ibm.pc:22506 comp.sys.intel:621 Path: utzoo!attcan!uunet!mcvax!enea!kth!draken!tut!santra!tukki!tarvaine From: tarvaine@tukki.jyu.fi (Tapani Tarvainen) Newsgroups: comp.sys.ibm.pc,comp.sys.intel Subject: Re: correct code for pointer subtraction Summary: Seems bug to me Keywords: C pointers Message-ID: <18123@santra.UUCP> Date: 14 Dec 88 19:38:25 GMT References: <597@mks.UUCP> <3845@pt.cs.cmu.edu> Sender: news@santra.UUCP Reply-To: tarvaine@tukki.jyu.fi (Tapani Tarvainen) Organization: University of Jyvaskyla, Finland Lines: 32 In article <3845@pt.cs.cmu.edu> ralf@b.gp.cs.cmu.edu (Ralf Brown) writes: >In article <597@mks.UUCP> egisin@mks.UUCP (Eric Gisin) writes: >-How come I can't find a compiler that generates correct >-code for pointer subtraction in C on 8086s? >-Neither Turbo, Microsoft, or Watcom do it right. [stuff deleted] >In addition to HUGE model, which someone already pointed out, I would like to >mention that K&R only guarantees valid results for pointer subtractions >between pointers to the SAME array. The same error occurs in the following program (with Turbo C 2.0 as well as MSC 5.0): main() { static int a[30000]; printf("%d\n",&a[30000]-a); } output: -2768 This seems perfectly legal according to either K&R or ANSI draft, so I think this is a bug. Tapani Tarvainen ------------------------------------------------------------------ Internet: tarvainen@jylk.jyu.fi -- OR -- tarvaine@tukki.jyu.fi BitNet: tarvainen@finjyu