This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Proper way to declare & use global variables



Hello again,

Using the f28377s launchpad, but I suspect this is more of a TI wide issue.

I seem to be having various issues with globals, particularly ones modified by interrupts or by function calls.  What is the proper declaration?

Currently I am using:

static volatile <type> <var_name>;

Interrupts, main, and other functions must be able to read and write to these variables.  I've seen mentions of a _codestart section of initialization related to the linker implementation, but I have not been able to locate these files (I have never had to change anything with a compiler/linker before.)  This article seems to indicate that there may be standards violations or additional overhead for globals. Can someone explain explicitly how I should declare my globals?

(The specific issue that I'm running into is that the global variables do not hold their value after a function call, outside of the main loop.  Interrupts and function calls bring in an empty struct and after the call the struct returns to its previous state as if no changes were made.)