2

Possible Duplicate:
How do function pointers in C work?

I've seen the usage of function pointers in C. I was wondering how they are exactly implemented behind the scenes in C? Are they just pointing to where the function instructions are stored? If so or otherwise, I would be grateful, if someone could diagrammatically show/elaborate (or point to some online resource) how they work?

Thanks in advance !

Edit : This question was not about usage of function pointers as explained in "How do function pointers in C work?". This is about the inner workings of how they are implemented.

Community
  • 1
  • 1
  • 3
    The pointer is just pointing to the memory location of the code to execute. Nothing more complicated than that... – Starkey Dec 04 '12 at 22:32
  • 2
    Take a look at http://stackoverflow.com/questions/840501/how-do-function-pointers-in-c-work – Yuriy Dec 04 '12 at 22:33

2 Answers2

1

yes, they are just a pointer to the location of the function, same as a pointer to data. However depending on the CPU architecture, when a function pointer is used, then the actual assembly can be quite different as functions can be stored in different types of memory compared to data.

Keith Nicholas
  • 43,549
  • 15
  • 93
  • 156
1

The article on Wikipedia ( http://en.wikipedia.org/wiki/Function_pointer ) fully explains it stating; "Instead of referring to data values, a function pointer points to executable code within memory. When dereferenced, a function pointer can be used to invoke the function it points to and pass it arguments just like a normal function call."

evanmcdonnal
  • 46,131
  • 16
  • 104
  • 115