Go Down

### Topic: Address of a function? (Read 5933 times)previous topic - next topic

#### franksmicro

##### Jan 22, 2011, 11:53 pmLast Edit: Jan 22, 2011, 11:54 pm by franksmicro Reason: 1
I was playing around seeing where the Arduino stores things in memory .  I used the following program:
Code: [Select]
`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:
Code: [Select]
`Address of a is 1AEAddress of b is 199Address of c is 8F4Address of d is 8F6Address of setup is 85Address of loop is 7EAddress of foo is 66Address 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.

Go Up