Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!rutgers!ucla-cs!zen!ucbvax!hplabs!hpcea!hpsrla!hpsrlc!darrylo From: darrylo@hpsrlc.HP.COM (Darryl Okahata) Newsgroups: comp.sys.ibm.pc Subject: Re: Microsoft C 4.0 large models Message-ID: <3320039@hpsrlc.HP.COM> Date: Fri, 31-Jul-87 12:01:25 EDT Article-I.D.: hpsrlc.3320039 Posted: Fri Jul 31 12:01:25 1987 Date-Received: Sun, 2-Aug-87 23:38:25 EDT References: <3225@cucca.columbia.edu> Organization: Network Measurements Div - Santa Rosa, CA Lines: 67 In comp.sys.ibm.pc, nwc@cucca.columbia.edu (Nicholas W. Christopher) writes: > I wrote a language and interpreter using Lex, YACC and curses on a vax > and am now attempting to get it to run under MSC 4.0 . The language > is window oriented and the PC-curses windows require 4K+. My code > bottoms out in 5 or 6 windows (I malloc space for other things as well) in > the small model. > > I tried compiling under a large model and the code ran for a while and then > froze. My question is, what are the things to worry about in large models? > Are there special considerations when passing arguements by address? Will > short integers behave? Where should I be looking (codeview just hangs so its > no help) ? > > Thanks, > /nwc > > P.S. I am really sick of seeing "Unknown Compiler Error, Contact Microsoft > Technical Support", I hope 5.0 does not loose as much as 4.0. > > ---------- The BIGGEST problem (in my opinion) of transporting code from UN*X to MSDOS is the usage of 0 (in UN*X) for NULL. In the small memory model, this is no problem, as the size of a pointer is the same size as an integer. However, in the large memory model, the size of a pointer (4 bytes) is TWICE the size of an integer (2 bytes). This becomes a problem when you try to pass a NULL pointer to a function. Let's say that you have a program fragment like: #include /* IMPORTANT!!!!! */ bomb(ptr) char *ptr; { if (ptr != NULL) *ptr = 'X'; } foo() { bomb(0); /* this blows up in the large memory model */ bomb(NULL); /* this works fine */ } Assuming the large memory model, when foo() calls bomb(0), two bytes (an integer) of zeros are pushed onto the stack. When bomb() checks the value of ptr, it is looking for a four-byte object (a pointer to char); the pointer offset will be zero (this is what was pushed onto the stack), but the pointer segment will be whatever is there on the stack and will, in all probability, be nonzero. The conditional expression in the if statement in bomb() will, as a result, be true (because the pointer segment is probably nonzero), and some random location in memory will be trampled. The result? Crash, boom, bang! Why does NULL work instead of a "0"? Well, when is included (this is included, isn't it?), NULL is either set to a "0" or "0L" ("0" for small memory models, and "0L" for large ones), which takes care of the problem quite nicely (and transportably, I might add). -- Darryl Okahata {hplabs!hpcea!, hpfcla!} hpsrla!darrylo CompuServe: 75206,3074 Disclaimer: the above is the author's personal opinion and is not the opinion or policy of his employer or of the little green men that have been following him all day.