This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Volatile keyword

IU have a variable which can be chyanged outside the interrupt but inside the ISR it is only read. Its value don't change in it. Should it be volatile.

Parents Reply Children
  • Note that the function that gets a pointer to a variable will not be able to generate any code based on any "auto" optimization rules. From a code perspective, it will just be a pointer to memory - and the majority of processors don't have any special, magic, memory reserved for "auto" variables.

    But the compilers do have sets of optimization rules that looks different, depending on what is known about a variable at the point of access. So the optimizers have different rule sets if they see a variable as auto, or global or indirectly accessed.

    Unless the function call is inlined, the variable will no longer be seen as an auto variable - but the pointer to it will be - when the execution enters the receiving function.