Thank you so much! -Robyn
Bob and I discussed pros and cons of Globals.
I use in some programs extensively globals, and use pointers
to them. Pariculary in cases where code space is challenged,
or execution speed. You define them once, they do not get pushed/
pulled on stack operations, just the pointers.
Note however this works great in reducing code size where native
machine size is 8 bit, and you have many ints and longs, especially
I think collectively we should do a sticky Globals vs Locals thread,
get everyones input, and put it in an ap note.
I've have experienced volatile memory data corruption (SRAM) on PSoC1 devices (which are programmed using the PSoC Developer IDE) when using local variables on complex code applications (I'm currently developing a Built In Self Test program for this kind of chips as one of the goals of my PhD thesis). This is a serious issue that limits the application of good coding practices, and decoupling between functions.
AFAIK is "volatile" for a local variable not a senseful selection because the variable cannot get altered from another program point (function or interrupt handler).
Can you please post a complete project that reproduces the bug you've found?
1 of 1 people found this helpful
and what about using local variables signed as externals?
At the university class, my professor warned us from using local variables, defined into functions, because of the problem of the stack.
I solved this problem by using global variables, defining them where they belongs to, and making them accessible also in some *.c file, defining them as extern.
Could it be marked as a good programming technique or not?
You may bust your stack by having too many local variables in use. This is (or should be) a common check at the end of a project to verify stack headroom. But nowadays the amount of sram available rarely limits the stack size.
For the sake of readability I (personally) group all external variables together and mark (as comment) where they are defined.
Instead of local variables on the stack you may use static variables.
No, this is a compiler limitation