- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you so much! -Robyn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
longs.
I think collectively we should do a sticky Globals vs Locals thread,
get everyones input, and put it in an ap note.
Regards, Dana.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Best Regards.
Emanuel Dri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Can you please post a complete project that reproduces the bug you've found?
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
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?
Bests!
Andrea
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
No, this is a compiler limitation
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
What precisely?