"deepak" <de*********@gmail.comwrote in message
news:11**********************@q2g2000cwa.googlegro ups.com...
>
1) Will it allocate memory for all the char's together or allocate for
first char. then for int then for float and after
this only second char in the function gets memory.
Generally, 'C' only guarantees that a given symbol (a varialble or an array)
is allocated contiguously. There are no guarantees about how different
symbols are allocated with respect to each other. One cannot make
assumptions about the address relationship between ib and ic, for example.
As other posters have pointed out, the notion of a "stack" does not appear
in the standards. This is probably true. In fact, some small processor
compilers have memory models where they don't use a stack. Instead, the
compiler analyzes the calling tree from top to bottom and puts automatics
into a static area of memory that is shared with all functions at the same
level of the calling tree. (This happens with the understanding that
recursion and corecursion are disallowed.) This is attractive in small
machines because instructions to reference memory with respect to the stack
pointer are very expensive, and one gets smaller code size by statically
allocating automatic variables.
2) If i declare variables where the size of al variables gone beyond
sizeof stack (assume it is 1000) what 'll
happen?
In a small machine (such as a microcontroller), bad things may happen (such
as rolling over the stack pointer with undefined behavior). But in a larger
machine (such as the x86 with a typical operating system),
a)The stack limits are hard to exceed, AND
b)The behavior is very reliable, such as program termination due to
exceeding stack allocation.
For a typical large machine, 1000 small variables or an array of 1000
elements on the stack in a single function would probably be tolerated. At
compilation, the processor has instructions to address memory in the stack
frame with very large offsets, and usually the only limit from the
compiler's point of view is whether it can choose the machine instructions
it wants/needs to get to the data. At runtime, typically the stack is
managed via the traditional virtual memory mechanisms. I doubt that a
practical program (one designed to do a computing job rather than to test
the stack limits) would run into these limits.
--
David T. Ashley (dt*@e3ft.com)
http://www.e3ft.com (Consulting Home Page)
http://www.dtashley.com (Personal Home Page)
http://gpl.e3ft.com (GPL Publications and Projects)