fermineutron said:
Ok, i want to figure this out:
Please provide context when you post a followup. Google Groups used
to have a bug that made this difficult, but it was corrected some time
ago. See <
http://cfaj.freeshell.org/google/>.
I happen to be reading this entire thread at once, but someone jumping
into the middle is going to have trouble following the discussion.
According to Kip R Irvine "Assembly Language for intel dased computers"
An executable file has to have 3 Segments, (Notice capitol S)
data Segment
code Segment
stack Segment
Furthermore depending on the .model directive, the Segments could be
equal to or greater than 1 segment (notice low case s)
That may well be true, but we don't discuss Intel based computers
here.
[snip]
So, when compiler translates the C code into asm, does it create the
data Segment, to store variables which are declared in functions?
does not create the .data Segment at all?
Am I missing something?
The C compiler does whatever it needs to do to make the program behave
in accordance with the semantics defined by the C standard. The
standard doesn't mention "segments", or "stack", or "heap". If the
generated code happens to use those constructs, that's fine, but they
may not even exist on the target system.
What the standard *does* say is that there are three "storage
durations": static, automatic, and allocated. Static objects (either
declared outside any function, or declared within a function with the
"static" keyword) exist throughout the lifetime of the program.
Automatic objects vanish on exit from the scope (function or block) in
which the're declared. Allocated objects are created by malloc() and
destroyed by free() (see also calloc() and realloc()).
Though the standard doesn't say so, an implementation may typically
place different limits on the total sizes of objects of the three
storage durations. If you run into such a limit, changing the storage
duration may avoid the problem. For example, you declared some very
large objects inside main(), so they have automatic storage duration;
changing them to static (by adding the "static" keyword, or by
declaring them outside main()) or allocated (by allocating them with
malloc() rather than declaring them directly) *might* solve your
problem. Be careful; changing the storage duration can change the
semantics of your program.
It's very common for the limit on automatic objects (which *might* be
allocated on a "stack") to be relatively low.