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.

MSP430FR2355: storage specifiers static and extern -- how to?

Part Number: MSP430FR2355


I have a variable defined in a.c (main) that is used in an ISR.  I also have a function in b.c that is called one time from main in a.c  The function uses the variable so in file b.c I give it a storage specifier of extern.  Now the problem I am running into is b.c modifies that variable BUT when the function in b.c is out of scope I lose the variable so I wanted to define it as "static extern" in b.c but Code Composer does not allow this. Has anyone run into this and if so how do you get around it?  Seems like it could be a common issue......

Thanks

  • Is it a global variable?

    It should also be volatile if used in an ISR.

    You should be able to define it as an extern in a header file and include the header in both files.

  • I will give that a try.....

    The ISR is not changing the variable only using it so I don't think volatile is necessary??  This one always confuses me....For instance if I assign a variable a register within an ISR I believe volatile is absolutely necessary HOWEVER if I have a variable change DUE to software (ie i++) in an ISR should it be volatile?  I'm guessing yes bcz the ISR is a random event (ie hardware) however it really is software changed and not hardware???

    Your thoughts

    Steve

  • You have to use volatile if the variable might be changed outside of the local context. So it sounds like you do not need volatile.

  • So does that mean if I have a function in file b.c that defines an external variable and changes that variable (software only no ISR) but then use that variable in main (a.c) I have to use "volatile"?  I thought that was what "static" was for?

    The compiler does not like when I declare a variable in .h file with extern, then use it in main (a.c) but it gets defined in function that exists in b.c.  Said function get's called from main....

**Attention** This is a public forum