Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the pointer value of a function pointer represent?

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!

like image 369
helpmelearn Avatar asked Oct 14 '10 05:10

helpmelearn


1 Answers

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.

like image 148
sharptooth Avatar answered Sep 22 '22 10:09

sharptooth