3

I have this type of definition

int (*af[10])(int , *a[10][10])(int,int)

and I had to "translate" it just like "this is pointer to function array size of 10" etc etc. I think that there is a mistake here, cause *a[10][10] doesn't have a definition type. Is this correct? Or this line can be translated properly?

Thanks in advance


Finally I found that the correct definition should be like this

int (*af[10])(int ,int (*a[10][10])(int,int))

which is correct and makes sense.

8
  • it's a syntax error because? missing definition type to the second array or? Commented Apr 2, 2014 at 8:50
  • Looks like a pointer to functions returning function pointers. Read it like "if I take af, give it an index from 0 to 9, dereference it, then call the result with two parameters of which one is an int and the other might be misspelled, and then call the result with two int parameters, then I get an int". Commented Apr 2, 2014 at 8:50
  • @yakamuki The type of a is incomplete. Commented Apr 2, 2014 at 8:53
  • 1
    For similiar questions, a look at cdecl.org might be helpful. Commented Apr 2, 2014 at 9:02
  • @glglgl cdecl.org thinks functions can return a function. For example, it will report int (*af[10])(int *[10][10])(int,int); as well-typed. This is misleading. Proper compilers are much more reliable in this case. Commented Apr 2, 2014 at 9:07

2 Answers 2

5

This is not a valid C declaration. First, the type of a is missing. But worse than that, it's as if (*af[10])(int , *a[10][10]) was returning a function (which is impossible).

Maybe you meant:

int (*(*af[10])(int , int *a[10][10]))(int,int)

Which would make af an array of 10 pointers to function receiving int and an array of 10 arrays with 10 pointers to int, and returns a pointer to function receiving two ints and returning an int.

EDIT:

Looks like the correct line is:

int (*af[10])(int ,int (*a[10][10])(int,int))

This makes af an array of 10 pointers to function receiving 2 parameters and returning int. The first parameter is an int, and the second is a multi-dimensional array (10x10) or pointers to function receiving 2 ints and returning an int.

In the future, you might want to check out cdecl.org to confirm your guess.

Sign up to request clarification or add additional context in comments.

7 Comments

yes, that's was what i thougt, but when i made a correction to these, i got a negative answer, as far this is correct syntax (according to them).
@yakamuki According to who?
i've been asked to translate this line for a course, that's why i'm so confused here..
@yakamuki If it was really like you showed, it's wrong. That's invalid C. Stuff it into a source file - it won't compile.
the funny thing is that i made the correction to the professor, he finally accepted this, but he kept asking to translate the wrong line..
|
0

I think that af is actually an array:

af[10]

The array contains pointers:

*af[10]

Those are pointers to functions:

int (*af[10])(...)

And the argument list has a syntax error, probably the comma after int is there by mistake:

int (*af[10])(int *a[10][10])

And the rest of the line is rubbish.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.