stack overflow at compile time

"Jatin Bhateja" <>
27 Apr 2006 09:14:54 -0400

          From comp.compilers

Related articles
stack overflow at compile time (Jatin Bhateja) (2006-04-27)
Re: stack overflow at compile time (RobertSzefler) (2006-04-27)
Re: stack overflow at compile time (Volker Barthelmann) (2006-04-27)
Re: stack overflow at compile time (Nitin Gupta) (2006-04-27)
Re: stack overflow at compile time (2006-04-27)
Re: stack overflow at compile time (glen herrmannsfeldt) (2006-04-28)
Re: stack overflow at compile time (=?ISO-8859-1?Q?Jan_Vorbr=FCggen?=) (2006-04-28)
[8 later articles]
| List of all articles for this month |

From: "Jatin Bhateja" <>
Newsgroups: comp.compilers
Date: 27 Apr 2006 09:14:54 -0400
Organization: Compilers Central
Keywords: storage, theory, comment
Posted-Date: 27 Apr 2006 09:14:54 EDT
Content-class: urn:content-classes:message


Is it possible at compile time to know whether there is a possibility of
stack overflow at run time? I feel that to some extent it is possible.

Let me explain it to you in detail. As compiler knows the stack offsets
for all the locals/temporaries/function arguments so at compile time one
can know the stack requirement of a particular function.

Now problem will occur in case of recursive function where if the
condition of recursion is not calculable at compile time then one cannot
make out the stack requirements.

Another thing is that as the size of executable comprises code and
global data it contains (of course not uninitialized global data) and at
run time heap and stack space is allocated to the running executable. So
if our OS is single tasking then only one program is present in memory
at run time and so the maximum size of stack that can be used is size of
the entire virtual memory. Thus under this circumstances if one knows
the stack size requirement of a program then we can tell at compile time
that stack overflow will occur or not.

Also this decision will be taken by the linker (of course it will use
some extra info about the stack requirement of a program that will be
emitted by compiler) as only at that time the exact size of object file
can be calculated by summing the size of each section of object file. We
need to know the size of exe/object file because maximum stack available
at run time will be virtual memory size - size of exe. Also no DLLs
will be allowed,

Please let me know your view on this.

Thanks and Best Regards,
Jatin Bhateja

Conexant Systems Inc
FC-2&4, Sector 16A,
Noida-201301, UP
Tel: 91 120 2512833, Extn @2408
[This looks to me equivalent to the halting problem. That means there are some
special cases you can solve, some of which are quite useful, but in general it's
undecidable. -John]

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.