- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Labels:
-
PSoC 5LP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
To reduce stack size do not declare local variables in main(). Since main() is a function they would be allocated on the stack.
But
The stack-size of a PSoC5 can be set at compile-time and so can be increased as needed and is set initially to 16K!!!. The problem of stack overflow in a PSoC5 environment is minimal if not non-existing (as long as the program behaves "normal").
Stack overflow is more a problem for PSoC1 or PSoC3 which both have a stacksize of 256 bytes only and is not adjustable.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
A useful reference -
http://www.embedded.com/design/prototyping-and-development/4025013/Say-no-to-stack-overflow
Regards, Dana.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
These are few good coding practices which are to be followed..............