Trying to understand what the pointer to function actually represent? Is it the address in the code segment where the function resides?
For ex: this piece of code:
#include <stdio.h>
void foo(void)
{
}
int main(void)
{
int a = 10;
printf("a's address: %p\n", &a);
printf("foo's address: %p\n", foo);
return 0;
}
... prints this:
[sh/prog-exercises/adam]:./a.out
a's address: 0xbfffb414
foo's address: 0x8048430
I guess I am a little confused with how exactly stack/heap of a process relates with the ELF data-segment/code-segment. Any helpful pointers would be really welcome. Also, my first question, so please be gentle, am really trying to learn. Thanks!
That's the address of the function entry point - start of its code. The a
variable is located on stack, so no surprise its address differs significantly - stack and code are assigned different code regions taht can be quite far apart.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With