Path: utzoo!utgpu!watmath!clyde!att!rutgers!deimos!uxc!uxc.cso.uiuc.edu!uxg.cso.uiuc.edu!uxe.cso.uiuc.edu!mcdonald From: mcdonald@uxe.cso.uiuc.edu Newsgroups: comp.sys.ibm.pc Subject: Re: correct code for pointer subtractio Message-ID: <45900182@uxe.cso.uiuc.edu> Date: 18 Dec 88 16:13:00 GMT References: <597@mks.UUCP> Lines: 50 Nf-ID: #R:mks.UUCP:597:uxe.cso.uiuc.edu:45900182:000:1197 Nf-From: uxe.cso.uiuc.edu!mcdonald Dec 18 10:13:00 1988 I tried compiling the following LEGAL C program (note the line struct six s[10000]; ) under various memory models of Microsoft C , and all failed, including Huge. (The declaration for "diff" was changed to K&R 1st edition style for later use. The original way does the same under Microsoft C). The problem lies ONLY in the huge model: one cannot expect this to work with both the -100 and +10000 answers, because one requires signed division, the other unsigned. struct six { int i[3]; }; int diff(p,q) struct six *p; struct six *q; { return p - q; } main(void) { struct six s[10000]; printf("%d\n", diff(s+10000, s)); /* 10000 */ printf("%d\n", diff(s, s+100)); /* -100 */ } Okay, then I tried compiling and running it using MicroWay NDP C on my Model 80. It gave the correct answer, just as I would expect it to. FINALLY, I changed "diff(s+10000,s)" to "diff(s+500000000,s)" (note, no change in the declaration of s), recompiled under NDP C and got 142086058 -100 which is wrong, just as I would have expected. Microsoft C is still broken. NDP C isn't - it is unequivocally, definitely, small model (32 bit ints, 32 bit pointers, no "far" keyword.) Doug McDonald