[comp.lang.c] TurboC 1.5 Stack check

haskins@s.cs.uiuc.edu (08/01/88)

I was testing the Stack Overflow Check feature of TurboC 1.5 and came up 
with something strange...here's the program:

#include  <stdio.h>
#include  <conio.h>
void call_routine(int);  /* prototype */

main()
{
   int j;
   j = 0;
   call_routine(j);
}

void  call_routine(int j)  /* 'modern' style */
{
   gotoxy(1,1);  /* top o' page */
   cprintf("level = %d",j);
   call_routine(j + 1);
}

Model size set to Huge, Test Stack Overflow ON (no duh)

Now, when this is run, it goes for 405 iterations, then prints a message
  Stack Overflow!
and quits, putting me back at the DOS prompt (or press a key to return...)
However, when I do a 'printf(..' instead of a 'cprintf(...)', it goes through
393 iterations, then prints 'lev' and hangs, allowing a warm start (thank
God).

What's the difference between whether cprintf or printf is used?  And in
general, should cprintf be used over printf for printing on the screen?
Please post replies here.

--------------------------------
Lloyd M. Haskins
Department of Computer Science -- University of Illinois
haskins@cs.uiuc.edu

haskins@s.cs.uiuc.edu (08/04/88)

So, nobody uses Turbo C around here?

Or are you just too proud to admit it?

------------------------
Lloyd M. Haskins
Department of Computer Science -- University of Illinois
haskins@cs.uiuc.edu

bobmon@iuvax.cs.indiana.edu (RAMontante) (08/05/88)

The following is a W-AG.  Kind corrections appreciated...

cprintf, being a "console" printf, is going directly to the hardware.  All
the code is TC-generated, so when the stack finally overflows your program
knows about it and the error-handling code succeeds.

printf uses operating-system (BIOS) calls.  Either by coincidence or for
some fundamental reason, your stack finally dies while BIOS code is
executing.  There's no way TC code could know about or cleanup after this,
and the BIOS doesn't have very sophisticated stack-error handling.  So it
dies.  You couldn't get to a reliable DOS prompt; DOS has died.
-- 
-- bob,mon				(bobmon@iuvax.cs.indiana.edu)
-- "half-witted:  it's better than no wits at all."

jim.nutt@p11.f15.n114.z1.fidonet.org (jim nutt) (08/06/88)

 -> From: haskins@s.cs.uiuc.edu
 -> Date: 4 Aug 88 14:57:00 GMT
 -> Message-ID: <207600002@s.cs.uiuc.edu>
 -> Newsgroups: comp.lang.c
 -> 
 -> 
 -> So, nobody uses Turbo C around here?
 -> 
 -> Or are you just too proud to admit it?

i use to... now i use zortech and am a much happier camper...

jim nutt
'the computer handyman'


--  
St. Joseph's Hospital/Medical Center - Usenet <=> FidoNet Gateway
Uucp: ...ncar!noao!asuvax!stjhmc!15.11!jim.nutt
Internet: jim.nutt@p11.f15.n114.z1.fidonet.org

swarbric@tramp.Colorado.EDU (Frank Swarbrick) (08/07/88)

In article <207600002@s.cs.uiuc.edu> haskins@s.cs.uiuc.edu writes:
>So, nobody uses Turbo C around here?
>
>Or are you just too proud to admit it?

I tried it but just forgot to post my results.

I got the same thing using both cprintf() and printf().  405, Stack Overflow,
or whatever it was.  So I don't know what the problem with yours is...

Frank Swarbrick (and, yes, the net.cat)           swarbric@tramp.Colorado.EDU
...!{ncar|nbires}!boulder!tramp!swarbric
"There's a Red under my bed, and there's a little yellow man in my head."
                                                              --The Kinks