On Wed, Sep 8, 2010 at 2:01 PM, thomas <[email protected]> wrote:
> Hi ,
>
> I hope someone can clarify this queries on function pointers :
>
> void (*func_ptr[](void)= {func1,func2,func3....funcN};
> What values will sizeof(func_ptr) and sizeof(*func_ptr) return ?

The (length of the array of function pointers x size of a function
pointer), and the (size of a function pointer) respectively.

The actual values will be dependant on your platform:

[...@pjhlaptop tmp]# cat x.c
#include <stdio.h>

void a(void){}
int* b(int i, float f, char* c){return 0;}

void (*p[])(void) = {a, a, a, a, a, a, a};
int* (*q[])(int, float, char*) = {b, b, b, b, b, b, b};

int main(void){
        printf("p:%d, *p:i%d\n", sizeof p, sizeof *p);
        printf("q:%d, *q:i%d\n", sizeof q, sizeof *q);
        return 0;
}

[...@pjhlaptop tmp]# make x
cc     x.c   -o x
[...@pjhlaptop tmp]# ./x
p:28, *p:i4
q:28, *q:i4


-- 
PJH

Reply via email to