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

method to avoid global variables

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.

Parents
  • You can avoid global variables by ensuring that you only ever pass anything to or from functions via parameters & return values.

    Generally, this adds an overhead that increases code size & reduces execution speed.

    With C51, passing parameters might reduce your RAM usage since the compiler can overlay these locations. If this in turn meant that you could use the SMALL model, instead of globals in XDATA, that could mitigate the performance & code size hit...

Reply
  • You can avoid global variables by ensuring that you only ever pass anything to or from functions via parameters & return values.

    Generally, this adds an overhead that increases code size & reduces execution speed.

    With C51, passing parameters might reduce your RAM usage since the compiler can overlay these locations. If this in turn meant that you could use the SMALL model, instead of globals in XDATA, that could mitigate the performance & code size hit...

Children
No data