I was playing around seeing where the Arduino stores things in memory . I used the following program:
int a;
int b=5;
void setup()
{
int c = 6;
int d = 7;
unsigned long val;
Serial.begin(9600);
val = (unsigned long) &a;
Serial.print("Address of a is "); Serial.println(val,HEX);
val = (unsigned long) &b;
Serial.print("Address of b is "); Serial.println(val,HEX);
val = (unsigned long) &c;
Serial.print("Address of c is "); Serial.println(val,HEX);
val = (unsigned long) &d;
Serial.print("Address of d is "); Serial.println(val,HEX);
val = (unsigned long) setup;
Serial.print("Address of setup is "); Serial.println(val,HEX);
val = (unsigned long) loop;
Serial.print("Address of loop is "); Serial.println(val,HEX);
val = (unsigned long) &foo;
Serial.print("Address of foo is "); Serial.println(val,HEX);
val = (unsigned long) *foo2;
Serial.print("Address of foo2 is "); Serial.println(val,HEX);
}
void loop()
{
delay(1);
}
void foo()
{
int i;
Serial.println("Test");
for(i = 0; i < 100; i++)
Serial.println(i,DEC);
}
void foo2()
{
Serial.println("Test");
}
This code produces (on ATMEGA328) the following output:
Address of a is 1AE
Address of b is 199
Address of c is 8F4
Address of d is 8F6
Address of setup is 85
Address of loop is 7E
Address of foo is 66
Address of foo2 is 5F
My question is - what do the addresses of foo and foo2 represent? These functions are in ROM, not RAM, and I confirmed by disassembling the elf file the Arduino compiler creates in its working directory that the ROM address does not correspond to these values. And I get the same value regardless if I use &func, func, or *func.