#include <stdio.h>
int global_var; //statically allocated as a global variable
static int static_var; //statically allocated but only accessible within file
void my_function(void){
static int my_static = 0; //statically allocated, accessible within my_function
int my_stack = 0; //allocated on the stack
printf("my_static:%d, my_stack:%d\n", my_static, my_stack);
my_stack++;
my_static++;
}
Answer:
my_static:0, my_stack:0
my_static:1, my_stack:0
my_static:2, my_stack:0
my_static:3, my_stack:0
my_static:4, my_stack:0
Reference
[1] http://coactionos.com/embedded%20design%20tips/2013/10/18/Tips-RAM-Flash-Usage-in-Embedded-C-Programs/
No comments:
Post a Comment