This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Global Variables vs. Pointers in Embedded Design

I've written a few 8bit embedded systems and the codebase I inherited and have expanded is basically 80% global variables (extern volatile), and than non-global control flags and logic variables as needed.

The end result, is that you end up with a lot void() functions to modify the global variables.

The systems run fine and the software quite readable and easy to work on, but I always have that design nag in the back of my head that I should be refactoring everything and pointer'ize the next design.

I don't have any religiosity about the memory usage aspect, the static memory is there to use as much as the heap is. It's more a question of as systems get larger, I suspect maybe the globals start to be more of a hinderance than you think? I've never gotten there in program size.

Do many of you experienced embedded software programmers use pointers extensively in your 8bits systems?

I can think of three possible use cases for using pointers in C51: linked lists (which we don't use) in this system, structs in place of independent variables and then functions with pointers to modify the strucs, maybe a double pointer if you absolutely need to modify a pointer but I can't fathom a situation in building a consumer product with an 8051 (maybe building an OS...).

I get that the functions can get re-used if you pointer'ize your code, but in one sense the functions are pretty trivial and one off in the embedded systems I've built. Very application specific stuff.

A couple of you guys who are still around C51 forum, what is your most compelling (or not compelling) use case for pointers in the code you have released?

Parents
  • FOR POSTERITY

    Holy treasure trove batman:

    ftp.ti.com/.../C51Primer.pdf

    Have you ever seen this C51 Compiler guide, from 1996! Somehow this thing is living on a TI FTP server. Talk about a dream resource for C51.

    This answers almost every question I've ever had (though sadly is a little silent on the pointer efficiency front!).

    I see the company now does paid consulting for embedded design, but holy cow this PDF is the best thing I've ever read in the last 18 months when thinking of how to improve my code on the 8051.

    They literally lay out everything from guys going from Assembly to C. So yes, they do actually explicitly explain the memory model. I get what you guys would debate on that front now. In my case, programs are so small that we aren't anywhere near resource constrained where we have to think of anything but the SMALL memory model.

    I have to say it does seem to support the keep-it-simple approach.

    Have you ever seen anything equivalent that this is detailed and conversational for the the ARM MDK? I find the KEIL documentation that is available online nowhere near as accessible and well written.

Reply
  • FOR POSTERITY

    Holy treasure trove batman:

    ftp.ti.com/.../C51Primer.pdf

    Have you ever seen this C51 Compiler guide, from 1996! Somehow this thing is living on a TI FTP server. Talk about a dream resource for C51.

    This answers almost every question I've ever had (though sadly is a little silent on the pointer efficiency front!).

    I see the company now does paid consulting for embedded design, but holy cow this PDF is the best thing I've ever read in the last 18 months when thinking of how to improve my code on the 8051.

    They literally lay out everything from guys going from Assembly to C. So yes, they do actually explicitly explain the memory model. I get what you guys would debate on that front now. In my case, programs are so small that we aren't anywhere near resource constrained where we have to think of anything but the SMALL memory model.

    I have to say it does seem to support the keep-it-simple approach.

    Have you ever seen anything equivalent that this is detailed and conversational for the the ARM MDK? I find the KEIL documentation that is available online nowhere near as accessible and well written.

Children