3 Replies Latest reply on Nov 23, 2012 7:26 AM by anushs_

    Prevent Stack Overflow

      There were multiple discussions related to Stack overflow.


      Here are some of the tips to have a good code -


      1. CASE statements are not the most efficient coding practice. This leads to increased use of stack space to store the interim results of each possible SWITCH state.


      2. IF statement with several decision points results in a byte being pushed to the stack for each comparison. Wherever  possible, replace this type of statement with the simplest form possible.


      3. Each passed variable is pushed to the stack for storage during a function call in C. Therefore, limit the number and size of passed variables to reduce stack usage. One way to  do this is to use global variables.


      4. Each local variable used by a function is allocated a byte on the stack on entry into the function. As a result, care is to be taken limit the number of local variables used by a function.