View Single Post
Go4Expert Member
11Mar2009,10:35  
jayaraj_ev's Avatar
Hi Guys ,
Sorry that i missed one Infor about the stack frame.

The stack frame would be like
____________________________
|_______Local Variables_______ |
|________Padding____________ |
|______Frame Pointer_________ |
|______Return Address________ |
|_Arguments/saved Temporaries_|

So to calculate padding = if ((Total size of local variables)% or mod 8) then padding = 4 else padding = 0;

so when You need to calculate Total size of a Stack frame : Size of all parameter + sizeof RA+ sizeofFP + Padding + sizeof Local

In the example

Code:
void fn(void)
{
int *ptr;
ptr = (int *)&ptr;
++ptr;    //Points to padding memory.
++ptr;   //points to FP where is stores previous FP
int* mnptr = (int *) *ptr;

--mnptr;  //points to Padding memof Main fn
--mnptr;  //points to Local variable.
*ptr = 300;
return;
} 

int main(void)
{
  int i = 0;
  fn();
  cout<<"I ="<<i<<endl;

  return 0;
}