Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!lll-winken!uunet!kddlab!titcca!sragwa!wsgw!socslgw!diamond!diamond From: diamond@diamond.csl.sony.junet (Norman Diamond) Newsgroups: comp.lang.c Subject: Re: When it is amoral... (Re: When is a cast not a cast?) Message-ID: <10226@socslgw.csl.sony.JUNET> Date: 8 May 89 03:46:29 GMT References: <2765@buengc.BU.EDU> <563@lzaz.ATT.COM> Sender: news@csl.sony.JUNET Reply-To: diamond@csl.sony.junet (Norman Diamond) Organization: /usr/lib/news/organization Lines: 27 In article <563@lzaz.ATT.COM> hutch@lzaz.ATT.COM (R.HUTCHISON) writes: >Re: addition of two pointers > >How 'bout in a binary search to find the middle char in an array of >characters? > > midpoint_pointer = (start_pointer + end_pointer) / 2; Yup, and if you have an array of ints? Let's see, half-way between the 1st and 6th elements, we have the 3.5th element. Well yeah, you've got chars not ints. Only the machine uses word addressing so that your pointers use some extra bits to indicate the offset within a word. If you're planning to leave your present employer before they ever have to port your code to another machine, you could do this: midpoint_pointer = (char *) (((unsigned long) start_pointer + (unsigned long) end_pointer) / 2); -- Norman Diamond, Sony Computer Science Lab (diamond%csl.sony.co.jp@relay.cs.net) The above opinions are my own. | Why are programmers criticized for If they're also your opinions, | re-inventing the wheel, when car you're infringing my copyright. | manufacturers are praised for it?