Path: utzoo!attcan!uunet!lll-winken!lll-lcc!ames!mailrus!iuvax!rutgers!njin!princeton!phoenix!rjchen From: rjchen@phoenix.Princeton.EDU (Raymond Juimong Chen) Newsgroups: comp.sys.ibm.pc Subject: Re: correct code for pointer subtraction (correction to typos) Message-ID: <5138@phoenix.Princeton.EDU> Date: 4 Jan 89 22:52:24 GMT References: <5137@phoenix.Princeton.EDU> Organization: Princeton University, NJ Lines: 31 I know it's bad form to follow up to one's own article, but the number of typos I found after posting it was embarrassing. > explicitly states "p-q is the numebr of elements between p and q". number > The additional code is really very simply. If the carry is clear, then simple > the accumulator contains the two-s complement of the > absolulte value of the byte difference. More clearly (and spelled correctly), the accumulator contains the two's complement of the absolute value of the number of bytes separating the two pointers. > But I suspect most people would argue that the original code > (which used the line printf("%ld\n", &a[30000] - a); ) is ANSI-conformant, "%d\n" ((oops)) > Let M be 2^sizeof(int), so that an unsigned can represent the values > 0 ... M-1, ... Of course, that should be ``Let M be 2^(number of bits in an int)''. Apologetically, -- Raymond Chen UUCP: ...allegra!princeton!{phoenix|pucc}!rjchen BITNET: rjchen@phoenix.UUCP, rjchen@pucc ARPA: rjchen@phoenix.PRINCETON.EDU, rjchen@pucc.PRINCETON.EDU "Say something, please! ('Yes' would be best.)" - The Doctor