2013-01-17 07:07 PM
I automatically feel stupid asking this question, I feel as if I should know this already. I'm not sure the relation volatile, static and other keywords have with variables that you may access all over the place.
So if I have a variable that I want to be able to read in one function and in another at what point would I want it to be volatile ? This is what I'm doing I have a var that is a simple char rx from the usart, then in my main i read that char and call the function. I debug and see that the char is in fact 'g' in the interrupt but when i get back around to my main its always 0x00-- defined in some .h file global to everythingvolatile static u8 debugChar; // debug char -- my int handler, works great ! void USARTx_IRQHANDLER(void){ if(USART_GetITStatus(Debug_USART, USART_IT_RXNE) != RESET) { debugChar = USART_ReceiveData(Debug_USART); printf(''\n\rDebug input command: %c\n\r'',debugChar); USART_ClearITPendingBit(USART2,USART_IT_RXNE); }}-- get back to main after leaving int handler and debugChar is 0 switch(debugChar) { case 'g': testGPIO(); break; }I have tried just static, i added volatile to it in an attempt to get it to work thinking volatile was a keyword for ''things that need to change quickly'' but i'm pretty sure thats wrong. Thanks for reading this far #declaration-vs-definition2013-01-18 01:19 PM
''
extern
definition !'' If it's extern, then it's a declaration You can't have an extern definition!2013-01-18 07:31 PM
I read the whole article, and all the ones referenced.
When I changed to using extern, the compiler did indeed find issues that it didnt before which I'm sure were causing me headaches. And my debug char works now, a simple extern declare.c define. (i actually had to edit this to change those :)2013-01-19 04:44 AM
You can't have an extern definition!
Depend on what one means. Prepending the definition of a (global) variable with ''
extern
'' is redundant, but otherwise correct.2013-01-19 06:27 AM
It seems you were right, some people take this 'software engineering' thing too seriously ;)