Quote:
Originally Posted by EricVanWyk
Wow, I just got pwnt. Very nice post.
Can you link us to more information on overlay variables? I am unfamiliar with them.
|
Thank you.
All the information I gave you was from the C18 Compiler manual, specifically page 20 of the User's Guide PDF on Kevin's site. (This is actually page 12 of the manual if you happen to have it printed out.)
One of the the key issues with overlay is that any sort of recursion is impossible. (e.g., you couldn't use it in the typical factorial implementation).
You will be given an error by the linker if this is the case though, so you shouldn't have to worry about random unknown errors popping up because of this.
The example you gave later in your post is correct (assuming I am inferring your intentions correctly). A static variable is used when you want the value of the variable to stay the same between function calls. An overlay or auto variable is used when you do not want that to be the case.
Quote:
Originally Posted by EricVanWyk
The optimization I was referring to was the distinction between using the stack and not using the stack. Usually when one of my students proposed using a static variable, this was the purpose.
|
If that was the case, then they would not be optimizing the code, they would most likely be breaking it.
Quote:
Originally Posted by TimCraig
If variables are "buddies", then group them in a struct. If the data needs to persist, then make the instance of the struct static. Functions that work on the data can then just take a pointer to the structure as an argument so one function can handle both left and right wheel data, for instance.
|
This is very good advice. Structs can help your code become much more organized. However, I personally prefer not using pointer arguments in robotics code, except for utility functions. If the structure needs to be used by more than one function make it a global or have it return a struct.