[comp.sys.ibm.pc] Borland Turbo C 1.5

root@mjbtn.MFEE.TN.US (Mark J. Bailey) (11/13/88)

Recently, I was working on a project that had started small and has
gradually grown to such that the medium memory model on my turbo
C 1.5 was insufficient to handle it.  I figured that I would just 
switch to the LARGE model and all would be well.  Well it wasn't.
When I went to the large model, some fgets statements that loaded
data into a string pointer that had some memory attached to it by
a malloc froze up the entire computer when it made the fgets call.

Has anyone else experienced this?  And if so, or if not so too, what
might be the cause of it?  I am not very familiar (as I should be)
with the main difference (advantages/disadvantages) of the MEDIUM
and LARGE models.  Would going to HUGE solve my problems or create
more?

Any help would be greatly appreciated.

Thanks in advance,

Mark.

-- 
Mark J. Bailey                                    "Y'all com bak naw, ya hear!"
USMAIL: 511 Memorial Blvd., Murfreesboro, TN 37129 ___________________________
VOICE:  +1 615 893 4450 / +1 615 896 4153          |         JobSoft
UUCP:   ...!{ames,mit-eddie}!killer!mjbtn!mjb      | Design & Development Co.
DOMAIN: mjb@mjbtn.MFEE.US.TN                       |  Murfreesboro, TN  USA

Don_A_Corbitt@cup.portal.com (11/15/88)

[changed memory model from small (16 bit) data pointer to large 
(32 bit) data pointer on IBM-PC, and program started hanging]

>Has anyone else experienced this?  And if so, or if not so too, what
>might be the cause of it?  I am not very familiar (as I should be)
>with the main difference (advantages/disadvantages) of the MEDIUM
>and LARGE models.  Would going to HUGE solve my problems or create
>more?
>Mark J. Bailey                                    "Y'all com bak naw, ya hear!"
>USMAIL: 511 Memorial Blvd., Murfreesboro, TN 37129 ___________________________
>VOICE:  +1 615 893 4450 / +1 615 896 4153          |         JobSoft
>UUCP:   ...!{ames,mit-eddie}!killer!mjbtn!mjb      | Design & Development Co.
>DOMAIN: mjb@mjbtn.MFEE.US.TN                       |  Murfreesboro, TN  USA
TC is tracking the ASNI standard.  This means that you should
	1) enable _all_ warning messages
	2) fix your code until all warnings are fixed
	3) #include header files for all library functions
Your problem is that you didn't include alloc.h, which defines malloc() as
returning a 32 bit pointer.  This was OK in 16 bit model, where TC assumed
malloc() returned an int, and converted it to a near pointer.  In large data
model, sizeof(pointer) != sizeof(int), so you must include the prototype for
any function that returns a pointer.
	Don_A_Corbitt@cup.portal.com "Where anyone can harass the net for $10"
	CrystalGraphics, Inc. 

psrc@poseidon.ATT.COM (Paul S. R. Chisholm) (11/17/88)

<"He seemed like such a nice man . . . and then he turned out to be a writer!">

In article <359@mjbtn.MFEE.TN.US>, root@mjbtn.MFEE.TN.US (Mark J. Bailey) writes:
> Recently, I was working on a project that had started small and has
> gradually grown to such that the medium memory model on my turbo
> C 1.5 was insufficient to handle it.  I figured that I would just 
> switch to the LARGE model and all would be well.  Well it wasn't.
> When I went to the large model, some fgets statements that loaded
> data into a string pointer that had some memory attached to it by
> a malloc froze up the entire computer when it made the fgets call.
> . . . Would going to HUGE solve my problems or create more?

It would create more.  In the Medium model, near (sixteen bit) pointers
are used for data.  In the Large model, fgets will return a far
(thirty-two bit) pointer.  If you didn't define fgets() (typically by
#include'ing <stdio.h>), it'll be implicitly declared to return an int.
The Large model will try to treat the (thirty-two bit) pointer in the
(sixteen bit) integer, and lose some of the address.

Solutions?  Include <stdio.h> and otherwise make sure you've declared
the functions you use.  (In Turbo C, -wnod or Options/ Compiler/
Errors/ Less Common Errors/ C ["No declaration for function
'XXXXXXXX'"] will tell you when something isn't declared; -wpro or Less
Common Errors/ D ["Call to function with no prototype"] will tell you
when a function is called before it's been fully declared with a
prototype.)

(By the way, if you've got lots of data but not too much code, try the
Compact model instead.)

>Mark J. Bailey, {ames,mit-eddie}!killer!mjbtn!mjb, mjb@mjbtn.MFEE.US.TN

Paul S. R. Chisholm, psrc@poseidon.att.com (formerly psc@lznv.att.com)
AT&T Bell Laboratories, att!poseidon!psrc, AT&T Mail !psrchisholm
I'm not speaking for the company, I'm just speaking my mind.

paik@ati.tis.llnl.gov (Yunki Paik) (11/20/88)

Use function prototyping and modern style of function declaration.
I ran into the same problem when converting from medium to large model.
The above measure worked perfectly.

	-yp