Path: utzoo!utgpu!attcan!uunet!lll-winken!xanth!kremer From: kremer@cs.odu.edu (Lloyd Kremer) Newsgroups: comp.lang.c Subject: Re: Malloc Trouble with Large Memory Model Summary: must use large-model libraries Message-ID: <8596@xanth.cs.odu.edu> Date: 21 Apr 89 20:24:25 GMT References: <208@sabin.UUCP> Organization: Old Dominion University, Norfolk, Va. Lines: 37 In article <208@sabin.UUCP> bjm@sabin.UUCP (Brendan J. McMahon) writes: >We have never had any need for any memory module other than the >default small. >We are switching to a new machine (intel 386 ) and our database libraries >(informix) only came in the large model. > >lrec[0]=(struct labelrec *)malloc(sizeof(struct labelrec)); >Compile Message: >Warning: cast of int expression to far pointer >Run time problems: >Printf(sizeof(struct labelrec)) = Some huge number >I am not familiar with memory modules, so many attempts to throw in >near/far keywords around different definitions did no good. Apparently, code compiled in large model is attempting to use the small model version of malloc(). Malloc is returning a 2-byte entity which is being cast unsuccessfully to a 4-byte entity. You must recompile using the large model version of malloc() (and all other library functions for that matter). No amount of casting with the near and far keywords will do any good here. A small model library routine is not capable of handling 4-byte pointers. It expects to be passed 2-byte pointers, and will return a 2-byte pointer. The sizeof() problem probably results from pointer subtraction performed on a mixture of pointer types (large and small). Even with implicit or explicit casting to far *, chaos will result, since the small pointer contains no valid segment information. -- Lloyd Kremer Brooks Financial Systems ...!uunet!xanth!brooks!lloyd Have terminal...will hack!