T
Tim Harig
the point is you can write C programs without knowing the deatils of
the stack layout (or even if it has a contiguous in memory stack) for
your particular implementation. You can even write programs not
I would almost agree with you. I agree that in theory programming in C
should theoretically not require any knowledge of memory models or stack
implementation details. Most of the time it is probably a moot point.
However, since stacks *may* have limitations imposed beyond what is
available in physical memory, it is possible to write 100% bug free,
standards complient code that still crashes because it overflows the
stack.
Imagine yourself as a "newbie" who has just had their program crash, not
because they wrote a bug in their code, but because in their implementation
there code overflowed the stack. What is your likely reaction? Would you
know how to find the problem? If you didn't know the program stack
existed, much less that it might be limited, how would you know to check
to see if it might have overflowed? You might even notice that it happens
when using larger data sets with higher levels of recursion; but, you can
see that your system still has plenty of memory left.
your particular implementation. You can even write programs not
knowing what the program is going to run on. Newbie questions are
Assuming you are careful not to use large amounts of local memory and avoid
using recursive algorithms this is probably true; but, that you do so
probably means that you know that these things help to prevent stack
overflows. Somebody who isn't aware of the problem might not have the same
instincts.
This is particularly true of those who come from languages that emphasize
the use of recursive algorithms, which is often true of those languages
that where designed in academic settings and tend to be highly based on
mathematical constructs.
It is also possible to be quite unaware of how much memory one is
actually creating locally. One of the reasons that some people do not
like typedefs is that type definitions of large structures (or objects in
OOP languages) may lure people into allocating them locally not realizing
how large the structures actually are.
knowing what the program is going to run on. Newbie questions are
often an indication of an unhealthy interest in implementation
details. Knowing how it /could/ be implemented can be useful just so
It is my experience that people make better decisions when they have better
information. This is true on the factory floor where having some idea of
what the next person down the line will encounter from your work may cause
you to lay the product in a different position that will be easier for them
to work with and it is true of programming where having some small idea
of what lies beyond the abstraction layers can help you make better
decsions in how you make use of that abstraction in your code.
details. Knowing how it /could/ be implemented can be useful just so
long as no one walks away thinking it /must/ be implemted that way.
I agree 100% and I don't expect people to be experts in their systems
implementation details. Knowing different ways in which stacks might be
implemented, what complications each may cause, and knowing what your
target implemenations may use can be valuable information.
Do you really look at the hardware stack when your program crashes? I
use a debugger. The last time I looked at a stack as a contiguous
series of memory elemts it was was running on a 680x0... ('20? '10?).
We weren't allowed to sell 68030s in some countries then...
1. I run my code through a debugger using test data whether or not
it crashes. It lets me see how my code is actually being used.
2. Its not uncommon for me to keep my eye on the stack dump to make sure
everything is working properly. I can often see problems before
they ever manifest any symptoms.
3. I don't always look at the stack in a dump format. More often I look
at the stack trace which automagically breaks it down into the
variables, types, and translated data of the variables that have
been pushed onto it as well as the address and identity of the
calling functional location. I know how my stack is organized
so if I see something corrupted, I can usually make a guess as
to what has overflowed and track back the cause of the overflow
from there. The stack trace ouput format does not however show
the magic numbers used for testing and protection of stack frame
boundries if they have been requested so it is occasionally
useful to see the stack in its full glory.