Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!rutgers!ucsd!ucbvax!decwrl!hplabs!hp-sdd!ncr-sd!ncrlnk!ncrwat!swdev!neil From: neil@swdev.Waterloo.NCR.COM (Neil A. Law) Newsgroups: comp.lang.c Subject: Re: near and far in MSC Message-ID: <366@swdev.Waterloo.NCR.COM> Date: 29 Jul 88 15:15:47 GMT References: <331@bdrc.UUCP> Reply-To: neil@swdev.Waterloo.NCR.COM (Neil A. Law) Organization: E & M Waterloo, NCR Canada Ltd, Waterloo, Ont, Canada Lines: 46 > > result = jess (LOAD_KB, "rules", 0); > >The code that handles the variable argument list looks like: > > va_start(ap); > while ((args[argno] = va_arg(ap, char *)) != (char *) 0) . . . > >I think the problem has to with the difference between near and far >pointers (eg. the terminating zero in the call will be interpreted as >a NULL pointer to char by the function jess). Could someone explain >to me how one programs under memory models other than the small one? > >John C. Lusth >Becton Dickinson Research Center >RTP, NC 27709 > >...!mcnc!bdrc!jcl John, Your problem is definitely in the difference between near and far pointers and some inconsistency in your coding. First, short pointers are 2 bytes in length, far pointers are 4. Second, if you analyze your call to "jess" the last parameter your are passing it is an int, not a pointer. When you call the function "jess" and pass it a "0" as the last parameter, the compiler pushes an int onto the stack (a 2 byte quantity). When "jess" computes the while statement, it is looking for a 4 byte quantity (char *). Since near pointers are the same length as an int in a small model your code works fine there. Solution, cast the 0 in the call to jess with a (char *), this way the compiler will always push sufficient information on the stack. Hope this helps. P.S. We had this problem in droves when we converted a 68000 application to run on the PC. On the 68K ints and pointers are the same size so comparisons of "ptr == 0" worked fine on the 68K but failed on the PC in large model. It took our developers a long time to track down all of these inconsistencies and taught us a valuable lesson, casting is important, especially in dealing with constants.