Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!jsgray From: jsgray@watmath.UUCP Newsgroups: comp.sys.atari.st Subject: Re: Bug in Alcyon C v4.14 (not a bug) Message-ID: <13802@watmath.UUCP> Date: Sat, 4-Jul-87 15:11:35 EDT Article-I.D.: watmath.13802 Posted: Sat Jul 4 15:11:35 1987 Date-Received: Sun, 5-Jul-87 01:06:07 EDT References: <4713@utah-cs.UUCP> Reply-To: jsgray@watmath.waterloo.edu (Jan Gray) Organization: U. of Waterloo, Ontario Lines: 22 Keywords: bug pointer arithmetic In article <4713@utah-cs.UUCP> sandra@utah-cs.UUCP (Sandra J Loosemore) writes: >I've just run across a rather annoying bug in Alcyon C v4.14 (the developer's >kit C): it has a hard time with adding a word-sized integer constant to >a pointer variable. My code originally looked something like > > STRUCTURE *this, *next; > next = this + sizeof(STRUCTURE); /* sizeof(STRUCTURE) = 8192 */ > >and it was generating code like: > > add.l #$80000000,R0 If you wanted 'next' to point to the next structure past 'this', you should have used 'next = this + 1'. 'next = this + 8192' advances next to the structure 8191 structures past 'this'. [K&R C Ref 7.4:] "The result of the + operator is the sum of the operands. A pointer to an object in an array and a value of any integral type may be added. The latter is in all cases converted to an address offset by multiplying it by the length of the object to which the pointer points." Jan Gray