AR# 33133


11 EDK - How do I use symbols to pass variables to use in C source code?


How can I use the linker variables such as stack and heap in my source code?


Use the extern keyword which declares a variable and specifies that it has external linkage; this means that the variable is visible in files other than the one in which it has been defined, in our case the linker script.

For example, the code below declares linker script variables using the external keyword so that they can be accessed globally.

In this simple code the stack and heap are defined and a print function is used to display stack and heap information.

extern int _stack_end;

extern int _STACK_SIZE;

extern int _stack;

extern int __stack;

extern int _heap;

extern int _heap_start;

extern int _heap_end;

int main(){

xil_printf("_stack_end: 0x%X", &_stack_end);

xil_printf("_STACK_SIZE: 0x%X", &_STACK_SIZE);

xil_printf("_stack: 0x%X", &_stack);

xil_printf("__stack: 0x%X", &__stack);

xil_printf("_heap: 0x%X", &_heap);

xil_printf("_heap_start: 0x%X", &_heap_start);

xil_printf("_heap_end: 0x%X", &_heap_end);

return 0;


AR# 33133
Date 12/15/2012
Status Active
Type General Article
People Also Viewed