views:

48

answers:

2

Hi,

I wanted to know in which section of the program are function pointers stored? As in, is it on the program stack or is there a separate section for the same?

void f(void){}
int main(void){
 int x[10];
 void (*fp)(void) = NULL;
 fp = f;
 return 0;
}

Now, will the address of x and fp be in the same segment of the program's stack memory?

+5  A: 

A function pointer is no different from any other pointer in terms of storage, which is again no different from any other variable. So yes, they'll all be stored together in the same place, which is the stack for local variables.

casablanca
+1  A: 

With a good compiler, they won't exist anywhere because their values are never used and contribute nothing to the output of the program.

R..