where the global and local variables are saved in memory of Aurix Micocontroller

Thread Starter

sophiefk

Joined May 21, 2019
1
I work with the Aurix MUC, I tried to read the contents of the memory after the execution of a program, to see what he wrote in the memoir

I noticed that when I use a global variable in a function, the new value of this global variable after processing in the function, is not written in memory.

Here is an example:

int a = 100;

void plus (int a)

{

a = a + 17;

}

int main (void)

{

plus(a);

return 0;

}

when I display the contents of the memory I find the value 100 of a

and I do not find the new value of a which is normally 117.

on the other hand if I do the calculation directly in the main like this

int a = 100;

int main (void)

{

a = a + 17

return 0;

}

like that I find the value 117 in the memory.

so I need to understand where are there save variables values used in the call functions?

and why the new variable of a is not written in memory,

and why the variables declared in local are not also written in the memory?
 

MrChips

Joined Oct 2, 2009
19,727
Variables (global and local) are saved in the application heap.
Local variables are allocated dynamically on a stack in the application heap but only last during the duration of the function.
 
Top