Type int * (*) (int *, int * (*) ())

int * (*) (int *, int * (*) ())

I would like to know what type it is ?, can anyone give an example of a declaration using this type.

any help would be great.

thank.

+5
source share
6 answers

This is a pointer to a function that returns int*and accepts int*and a pointer to a function that returns int*(and accepts an undefined number of parameters, see comments).

In some example (it doesn’t look very good, it is simply designed to contain the specified declaration):

#include <stdio.h>

static int a = 10;
int* f1() {
    return &a;
}

static int b;
int* f2(int *j, int*(*f)()) {
    b = *j + *f();
    // this is just for demonstrational purpose, such usage
    // of global variable makes this function not thread-safe
    return &b;
} 


int main(int argc, char *argv[]) {
    int * (*ptr1)();
    int * (*ptr2) (int * , int * (*)());
    ptr1 = f1;
    ptr2 = f2;

    int i = 42;
    int *pi = ptr2(&i, ptr1);
    printf("%d\n", *pi);

    return 0;
}

// prints 52
+19
source

cdecl - your friend:

$ cdecl explain 'int * (*x) (int * , int * (*)())'
declare x as pointer to function (pointer to int, pointer to function returning pointer to int) returning pointer to int
+7

... cdecl.org, -

int * (*) (int *,int *(*)())
  • (int *, int()()) - (*)() - int()() - , int
  • (int *,...) - , int, - ---return-pointer-to-int
  • (*) (...) -
  • int * (*) (...) - --return-pointer-to-int

: , , int, - ------int -- .

: C, -, - ,

int *(*x)(int *,int *(*)())

: x ( int, , int), int

, , , .

+2

, " ", , . , , . , , .

, :

  • "()" ", "
  • "[n]" " n"
  • "*", "" "

" ":

  • .
  • .
  • , .
  • , .
  • , .
  • , .

:

int n[10];

n. [10], "array of 10". int. ,

n - " 10 ".

int *n[10];

n. [10], "array of 10". , *, " ". . , , , int. , :

n - " 10 ".

int (*pf)();

- pf. pf. pf *. , - " ". , (). , ", ". int. , :

pf " , int"

int *(*pf)();

pf . pf. - *, - " ". (), ", ". *, " ". int:

pf " , int".

, pf. : int *x int *(*y)(). , . , :

int *(*pf)(int *x, int *(*y)());

pf , int. pf . x int. y , int.

+1
typedef int* (*fptr)();    
int* foo(int* p1, fptr p2);

foo .

0

!. C:

void (*
     signal(int sig, void (*func)(int)))(int);

, typedef'd:

typedef void (*sig_t) (int);
sig_t signal(int sig, sig_t func);

, , int sig_t sig.

0

All Articles