Path: utzoo!utgpu!utstat!jarvis.csri.toronto.edu!mailrus!ames!xanth!lll-winken!uunet!nfsun!libove!root From: root@libove.UUCP (Jay M. Libove) Newsgroups: comp.lang.c Subject: Re: Malloc Trouble with Large Memory Model Message-ID: <250@libove.UUCP> Date: 23 Apr 89 14:00:53 GMT References: <208@sabin.UUCP> Organization: Libove.UUCP Lines: 52 From article <208@sabin.UUCP>, by bjm@sabin.UUCP (Brendan J. McMahon): > We have never had any need for any memory module other than the > default small. I'm _very_ surprised. > We are switching to a new machine (intel 386 ) and our database libraries > (informix) only came in the large model. > So all programs that use these have to be compiled with -Ml2 (large model 286). > (Or do they?) They do. Otherwise the loader can't deal with it. I think that there may be some way around this, but it is much easier to simply fix code problems that small model let's you get away with (I'll explain below) and recompile, than it would be to munge together different models. > lrec[0]=(struct labelrec *)malloc(sizeof(struct labelrec)); > Compile Message: > Warning: cast of int expression to far pointer What's actually happenning here, most likely, is that nowhere above the first call to malloc() was malloc() declared as an extern function that returns type (char *) e.g. extern char *malloc(); so the compiler is using the implicit int return rule to guess that malloc() returns an int - which on the 8086 and 80286 compiler is a 16 bit quantity - and you're assigning the return value of a malloc() call to a pointer - which on the 80286 and 80386 is a 32 bit quantity - and are therefore _losing_ 16 bits of address significance... I'm _really_ surprised that you didn't get a core dump - on an 80286, you would have gotten a core dump... my guess is that with the much larger and better managed memory segments of the 80386, the problem did not manifest itself as clearly as i would have on the 80286. > Thanks for any help! You're welcome. > Brendan J. McMahon > Sabin Metal Corp. | Refiners of Precious Metals | Hardware Trouble? > Scottsville, NY | ****** Au Ag Pt Pd Rh ****** | Give us a call, we'll > 716-538-2194 |lazlo!sabin!bjm || ritcsh!sabin!bjm| melt your trouble away ------------- Jay Libove jl42@andrew.cmu.edu, libove@cs.cmu.edu, 5731 Centre Ave, Apt 3 gateway.sei.cmu.edu!libove!libove, jl42@andrew.BITnet, Pittsburgh, PA 15206 psuvax1!pitt!darth!libove!libove, (412) 362-8983 or uunet!nfsun!libove!libove