Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Compilers LCC > Re: What can I ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 12 of 23 Topic 955 of 1070
Post > Topic >>

Re: What can I do?

by "Rod Pemberton" <do_not_have@[EMAIL PROTECTED] > Jun 2, 2007 at 10:28 PM

"jacob navia" <jacob@[EMAIL PROTECTED]
> wrote in message
news:4661ea93$0$27383$ba4acef3@[EMAIL PROTECTED]
> Consider this program:
> int fn(int a)
> {
>
>          if (a == 6 || a == 7 || a == 4 || a == 67 || a == 78 &&
>          a == 6 || a == 7 || a == 4 || a == 67 || a == 78 &&
>          a == 6 || a == 7 || a == 4 || a == 67 || a == 78 &&
>          a == 6 || a == 7 || a == 4 || a == 67 || a == 78 &&
>
> (4955 lines exactly the same as above elided)
>
>          a == 6 || a == 7 || a == 4 || a == 67 || a == 78 &&
>          a == 6 || a == 7 || a == 4 || a == 67 || a == 78 )
>                  return 1;
>          return 0;
> }
>
> This program makes the lcc compiler crash with stack overflow.

Are you able to detect the overflow prior to the overflow?

> Fixing this would have to change drastically the design of the
> compiler. In the other hand leaving this as is would leave a
> compiler that can crash in some cir***stances.
>

Increasing the stack size would require drastic redesign?

> What can I do here?
>

If you can detect overflow and underflow of the stack prior occurrences of
them, you might be able to fix the problem.  Assuming the stack is large,
much of the data it contains won't be used for a while.  I.e., only the
top
elements of the stack are acting like a stack, the rest are just being
stored until the program gets back around to using them.  So, you could
create another place to store them: an overflow buffer.  Allocate enough
memory for another stack.  Copy the stack contents to the overflow buffer.
Reset your stack pointers (stack is now empty).  Go back to using the
stack.
When the stack is about to underflow, copy the overflow buffer back. 
Reset
your stack pointers (stack is now full).  Go back to using the stack.  If
the stack is pu****ng and poping alot right around the overflow condition,
you'll end up thra****ng the stack.  You might choose to copy 3/4 of the
stack in that case so that some elements are left to prevent the
thra****ng.

> Is this legal C?
>

Does that really matter?

  (BTW, DJGPP and OW fail too...)


Rod Pemberton
 




 23 Posts in Topic:
What can I do?
jacob navia <jacob@[EM  2007-06-03 00:09:22 
Re: What can I do?
Gregor H. <nomail@[EMA  2007-06-03 00:16:04 
Re: What can I do?
Gregor H. <nomail@[EMA  2007-06-03 00:26:29 
Re: What can I do?
Gregor H. <nomail@[EMA  2007-06-03 00:39:23 
Re: What can I do?
jacob navia <jacob@[EM  2007-06-03 09:06:35 
Re: What can I do?
Gregor H. <nomail@[EMA  2007-06-03 15:29:35 
Re: What can I do?
John Nagle <nagle@[EMA  2007-06-02 15:34:37 
Re: What can I do?
Giorgos Keramidas <ker  2007-06-03 15:33:48 
Re: What can I do?
richard@[EMAIL PROTECTED]  2007-06-02 22:23:21 
Re: What can I do?
jacob navia <jacob@[EM  2007-06-03 09:08:00 
Re: What can I do?
Eric Schmidt <eric4129  2007-06-02 16:54:03 
Re: What can I do?
"Rod Pemberton"  2007-06-02 22:28:28 
Re: What can I do?
richard@[EMAIL PROTECTED]  2007-06-03 15:58:59 
Re: What can I do?
"Rod Pemberton"  2007-06-03 12:43:25 
Re: What can I do?
Hallvard B Furuseth <h  2007-06-03 21:22:48 
Re: What can I do?
Cesar Rabak <csrabak@[  2007-06-03 02:18:53 
Re: What can I do?
Keith Thompson <kst-u@  2007-06-03 00:00:00 
Re: What can I do?
jacob navia <jacob@[EM  2007-06-03 09:15:16 
Re: What can I do?
CBFalconer <cbfalconer  2007-06-03 02:09:14 
Re: What can I do?
Dave Hanson <drhanson@  2007-06-03 14:53:50 
Re: What can I do?
Hallvard B Furuseth <h  2007-06-03 21:44:46 
Re: What can I do?
Keith Thompson <kst-u@  2007-06-03 13:08:36 
Re: What can I do?
"christian.bau"  2007-06-03 14:32:10 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Oct 10 23:24:25 CDT 2008.