Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!cs.utexas.edu!helios!tamuts!x041sc From: x041sc@tamuts.tamu.edu (Sean Malloy) Newsgroups: comp.os.msdos.programmer Subject: Re: Memory Models in TC2.0 Message-ID: <16856@helios.TAMU.EDU> Date: 4 Jun 91 16:36:08 GMT References: <16854@helios.TAMU.EDU> Sender: usenet@helios.TAMU.EDU Organization: Texas A&M University Lines: 54 I'm sure that this is a question that should be included in a FAQ for this group, but I couldn't find a general FAQ in the message list. I'm writing a (rather large) application in Turbo C 2.0 and I've come to the point where I need to use either the Compact or Large memory models instead of the small. I've gone through my code and changed all the pointers and functions that deal with data that is malloc()'d to be far (ie OBJECT far *draw_haxis(OBJECT far *BOX) { ) and the compiler seems to be quite happy. No warnings; no errors. (I realize that my life would be much easier using an OOL, but my company won't buy C++ right now... ;-(. The following fragment works under the small memory model, but not under the Compact, Large, or Huge models, and I'm going nuts trying to figure out why. Any suggestions? ------------------- Begin Fragment -------------------- OBJECT far *new_object(enum obtype type) { OBJECT *ptr; coor d; d.x = 0; d.y = 0; if ((ptr = ((OBJECT far *)malloc(sizeof(OBJECT)))) == NULL ) { perror("New_object failed to allocate memory. ABEND"); exit(0); } if (obhead == NULL) { obhead = ptr; endob = ptr; } else { endob->next = ptr; ptr->prev = endob; endob = ptr; } ptr->type = type; ptr->parent = NULL; ptr->child = NULL; ptr->next = NULL; -----------------End Fragment--------------------------------- ...where of course OBJECT is a struct (with pointers to other structs, unions, etc -- a data structure from hell) My problem is that the assignment "ptr->type = type;" fails to change the value of ptr->type, even though malloc seems to work correctly (According the integrated debugger inside Turbo C) and my program fails because of this little inconvience. Do I have to declare my structs as far data items? If so, can someone provide me with an example - I can't seem to find one in any of my references... Thanks -Sean .