TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: Mike Phillips
from: Henk den Adel
date: 1997-03-22 22:22:14
subject: trap 0005

Hi Mike,

You answered me:

 HdA>> I would appreciate if anyone could explain me why the stack is not
 HdA>> automatically chosen to be sufficiently large,

 MP> The reason is that the compiler does not know how large to make the
 MP> stack, so it uses a default size.

Now i'm puzzled. Maybe you can help me out of the maze. The way i was
thinking is as follows. Languages like C urge one to declare variables, in
contrast to e.g. Fortran, where the motto is: if you need one, just use it,
you don't have to declare it. So there must be a reason for the necessity
to declare variables in a language like C. Another fact: all declarations
must be contained in the first part of a function, before the first
executable statement, i.e.

   float x, y;
   y = sin(x);
   int i;

produces an error during compilation. Why? I think the compiler wants its
variables neatly bundled, so it can allocate adresses and the accompanying
amount of memory, without having to gather variables all over the place.
Furthermore, since sizeof(struct whatsoever) produces the right size of
more complex type of variables, such as structs, the compiler should be
able to determine the amount of memory which is needed for a struct, by
sheer interpretation of the formal declaration of the struct, as provided
in the function or its include files. BTW, i have declared my struct as a
variable, not as a pointer.

Could you be so kind to indicate which step in my reasoning is incorrect?

 MP> That function needs 40k of stack. What if that function called a function
 MP> in another source file that needs another 40k of stack. How is the
 MP> compiler to know this?

Just add another 40 kB of stack?

 MP> Anyways, it's the linker that actually makes the stack definitions, and
 MP> it doesn't know how much you've used.

In my opinion the compiler can determine how much memory is needed to
contain the variables which have been declared. Isn't that it what
declarations are meant for? I can't believe the more misantropic
suggestion: to be able to generate error messages when an unfortunate
programmer forgets a variable to declare?

 MP> Just make your stack large enough.

Murray Lesser wrote me that excessive stack does not hurt my resources, if
the compiler is good, so that will be the solution.


tnx, 73 es cuagn,
 Henk

--- GoldED 2.50+
* Origin: Henks Toolbox (00-06h), Mail only (2:286/415)
SEEN-BY: 50/99 54/99 270/101 620/243 625/155 711/401 413 430 934 712/311 407
SEEN-BY: 712/505 506 517 623 624 704 713/317 800/1
@PATH: 286/415 4 700 280/801 270/101 712/624 711/934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.