Your SlideShare is downloading. ×
Program activation records
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Program activation records

2,792
views

Published on

Function Calls and Program Activation records / Stack Frames

Function Calls and Program Activation records / Stack Frames


0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,792
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
47
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Nitin Reddy Katkamnitinkatkam.comn4express.comknreddy.com
  • 2.  Also called Stack Frames Activation records are entries on a call stack They maintain information about functions being called and their return locations They also contain parameters and local variables
  • 3.  Contains an activation record for each function that is called Grows backwards (higher memory address to lower memory address) Has a stack pointer pointing to the top of the stack
  • 4. void function2() { … Each function call function2(); adds an activation …} record to the call stack Stackvoid function1() { Pointer …} function2_1 function2int main() { … function1 function1(); …} main
  • 5. Register Values Local VariablesCaller’s Frame/Base Pointer Return Address Parameters
  • 6. int main(){} main
  • 7. void func1(int a){int x;}int main(){func1(3); func1} main
  • 8. void func1(int a){int x;} Register valuesint main() int x{ Frame ptr of main()func1(3); func1 Program counter of} main() main int a
  • 9.  An activation record is created on the call stack when a function is called (winding). The activation record is removed from the call stack when the function returns (unwinding).  “Why can’t you return a pointer to a local variable declared within a function?”
  • 10.  Recursive function calls will add an activation record to the stack for each call  “What is a stack overflow?”
  • 11.  You can use pointers to access the activation record Example:  void func(int a) { printf(“Return address: %xn”, &a-1); }
  • 12.  Email: k.nitin.r [at] gmail