Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

8
  • Thanks for such an extensive answer so quickly. I'll have a look and mark as read once I fully grasp it. At least it give me some good pointers. I seem to be struggling a bit which level of abstraction to use for microcontrollers. Turning back to C after a rather long time of Python and friends, it's interesting to see how poor C's memory management is, and how poor Python's instance protection are. Your answer helps me understand what sort of introspection I can expect from C, especially on an Arduino platform with few high-level libraries. Commented Mar 25, 2021 at 19:35
  • @MacFreek: none of the code I posted (or that you posted) is C. It is all C++. (And C++ is not modern C, they are two different languages). Look up "RAII" for how you should deal with memory management/object lifetime management. A lot of what you'll find won't be a great fit for small embedded projects, but the core idea is important. (The acronym sucks though.) Commented Mar 25, 2021 at 19:43
  • You are right. I used "C" because my Arduino code mostly uses plain functions and globals, rather than classes (which is fine for this purpose). Commented Mar 25, 2021 at 20:12
  • I'm not sure if this is a C vs. C++ syntax, or historic/modern constructs, but I noted that the Arduino IDE allows archaic constructs. For example, you can leave out the this-> in methods, or leave out the std:: prefix for type definitions. I found the hard way when delay() in my method did not call the Arduino function, but this->delay(). Would there be a way to make the IDE more strict, and only allow recommended constructs, so I only learn things the right way? Commented Mar 25, 2021 at 20:15
  • Thanks for your code examples. I now understand that I need a wrapper function, preferably in the stateful class with the called method. I was trying to solve it in the calling instance, without wrapper. Commented Mar 25, 2021 at 20:17