Malloc Trouble with Large Memory Model

Lloyd Kremer kremer at cs.odu.edu
Sat Apr 22 06:24:25 AEST 1989



In article <208 at sabin.UUCP> bjm at 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!



More information about the Comp.lang.c mailing list