So the Arduino environment has the following template code when you start up a new project:
void setup() { //code to be run at startup }
void loop() { //run forever }
Suppose I define a class at the top of my "sketch" like so:
struct Foo { void do_it() { return 1; } };
I then try to create a "global" instance of the class outside the "setup" section:
Foo foo;
This compiles fine, except that when you attempt to use "do_it" from within the "loop" section the code doesn't seem to execute properly.
If I do the following:
Foo *foo;
void setup() { foo = new Foo; }
It works as expected, but then...something? is being placed into heap memory. My expectation would be that on a Harvard architecture uP, the only things being put on the heap when a new object is instantiated would be the non-const class member variables with static storage duration, as the code has its own program memory, but that doesn't appear to be what is happening.
Any insight into what avr-gcc is actually doing in this case would be appreciated.