I want to know method, How to avoid global variable in c microcontroller programing? or method to make global variable invisible. Is there any perticular functions in built in c library?, that could be supportive to avoid global variables or hide global variables.
Find out for yourself: take a largish project and make all the variables global, then report back with your findings. Who said anything about all the variables ? I do, of course, use lots of local variables, what I reacted to is the idiotic C thing that some teach "under penalty of severe bodily harm, do not use any global variables". How would you communicate smartly between an ISR and the main without a global variable. Erik
I just recall an incident. I worked bnriefly at a place thet had the "under penalty of severe bodily harm, do not use any global variables" rule. I had to make a variable accessible to 2 functions (b and y) and was told to do it this way:
void main (void) { struct st ... unsigned char ch ... funca (*st) funcv( *st) ... } funca (*structure) { ... funcb (*structure) ... } funcb (*structure) { .... ralph = st.ch ... } funcv (*structure) { ... funcw (*structure) ... } funcw (*structure) { ... funcx (*structure) ... } funcx (*structure) { ... funcy (*structure) ... } funcy (*structure) { .... st.ch = george ... }
unsigned char ch void main (void) { funca () funcv() ... } funca () { ... funcb () ... } funcb () { .... ralph = ch ... } funcv () { ... funcw () ... } funcw () { ... funcx () ... } funcx () { ... funcy () ... } funcy () { .... ch = george ... }
"Who said anything about all the variables ?" I think you know who it was: me. "I do, of course, use lots of local variables" Ok, ask yourself why you made those variables local rather than global. "what I reacted to is the idiotic C thing that some teach "under penalty of severe bodily harm, do not use any global variables"" Who said anything about not using any global variables? "How would you communicate smartly between an ISR and the main without a global variable." Oh, that's easy. Loop back some port pins.
Who said anything about not using any global variables? the OP Erik
"Who said anything about not using any global variables? the OP" No he didn't: "I want to know method, How to avoid global variable in c microcontroller programing? or method to make global variable invisible. Is there any perticular functions in built in c library?, that could be supportive to avoid global variables or hide global variables." I don't see the words 'all' or the phrase 'not using any' in there.
http://www.bartleby.com/61/96/A0549600.html defines avoid as To stay clear of; shun. That means all Erik
"defines avoid as To stay clear of; shun. That means all" So you think that these two phrases are semantically identical? "Avoid global variables" "Avoid all global variables" I think your grasp of the language is better than that.