0

I have a function which I would like to pass to another function as an argument (let's call it funX). Here's funX prototype:

void funX(const unsigned char *, unsigned char *, size_t, const somestruct *, unsigned char *, const int);

and my function (lets call it funY) which calls funX:

unsigned char * funY(unsigned char *in, unsigned char *out, size_t len, unsigned char *i, void *k, int ed, void (*f)(unsigned char *, unsigned char *, size_t, const void *, unsigned char *, const int))
{
    f(in, out, len, k, i, ed);
}

But I have some warnings while compiling:

test.c: In function ‘main’:
test.c:70:5: warning: passing argument 7 of ‘funY’ from incompatible pointer type [enabled by default]
test.c:11:17: note: expected ‘void (*)(unsigned char *, unsigned char *, size_t,  const void *, unsigned char *, const int)’ but argument is of type ‘void (*)(const unsigned char *, unsigned char *, size_t,  const struct somestruct *, unsigned char *, const int)’
3
  • 1
    Use typedef for signatures as suggested here. This makes declaring a function parameter easier. Commented Sep 1, 2013 at 18:34
  • the error message seems pretty clear, the function pointer type does not correspond to the function you want to pass. Commented Sep 1, 2013 at 18:39
  • The function pointer parameter in funY declaration is not the same type as the type of funX. Just the first difference: the first arg to funX is a const unsigned char * whereas the first arg of the function pointer is a unsigned char *. Commented Sep 1, 2013 at 18:40

3 Answers 3

3

See the warning and compare the prototypes

Expected:-

void (*)(unsigned char *,       unsigned char *, size_t,  const void *,              unsigned char *, const int)

Provided :-

void (*)(const unsigned char *, unsigned char *, size_t,  const struct somestruct *, unsigned char *, const int)
Sign up to request clarification or add additional context in comments.

Comments

2

Did you read the entire error message?

You have some const- and other type mismatches (e. g. a pointer-to-struct instead of void *, etc.) in the signature of the two functions. Function types are compatible only if their signatures match exactly.

Comments

1

Your signatures seem to be different. See below.

void funX(const unsigned char *, unsigned char *, size_t, --> const somestruct * <--, unsigned char *, const int);

void (*f)(unsigned char *, unsigned char *, size_t, --> const void * <--, unsigned char *, const int)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.