Go Down

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


Jan 22, 2011, 11:53 pm Last 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;
 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()

void foo()
 int i;
 for(i = 0; i < 100; i++)

void foo2()

This code produces (on ATMEGA328) the following output:
Code: [Select]

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.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131