Pages: [1]   Go Down
Author Topic: Address of a function?  (Read 1468 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 7
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I was playing around seeing where the Arduino stores things in memory .  I used the following program:
Code:
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:
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.
« Last Edit: January 22, 2011, 05:54:36 pm by franksmicro » Logged

Pages: [1]   Go Up
Jump to: