1. ## Function declarations

Hi, Quick question. Was looking in to some of the complex function declaration topic and came across this question. I have two answers for this. Just wanted to make sure that I am right.

Here is the question which i came across, where i need to write the function declaration for it.

Declare a pointer to a function taking an int and a pointer to int and returning a pointer to an array of pointer to char.
And here are my two solution

Solution 1
Code:
`char ** (*f)(int, int *);`
Solution 2
Code:
`char *[] (*f)(int, int *);`
I am confused, when it says "pointer to an array of pointer to char". Will this be a pointer to a pointer as well.

Is my understanding of that question is right. Please put me in a right direction.

Thanks a lot

ssharish

2. Yeah, that's the part that had me scratching my head too...
I think it's just very badly written. The way it's written makes it sound like they want a char*** returned; but since triple pointers are extremely rare, I'd say it's just asking for a char**.

3. Sounds like a triple char pointer to me.

...a pointer to an array of pointer to char.
Going backwards.....

char *
char **
char ***

4. Right understood now, the mistake which i was doing was solving that through left to right. Thanks a lot for both of you for a quick reply.

Is there any application of using that sort of Declaration. Just curious to know . Have u any found come across using just a function declaration.

ssharish

5. You need function pointers for DLLs if you are going to dynamically load and use a DLL (at runtime, of course).

6. Sorry to bug u all again. I have one more question. I came across this question as well. And I have solved it as well. Just tell me am I right. This is the question

Declare a function which takes an array of function pointers and returns a function pointer. All function pointers are to functions which take an int and return a pointer to char.
Solution
Code:
`char * ( *fun( *[] ) )( int );`

You need function pointers for DLLs if you are going to dynamically load and use a DLL (at runtime, of course).
OK it would be normally used int developing libraries. In think OpenGL uses a lot ofd those isnt?

Thank you

ssharish

7. This is kind of messy, and I'm not checking my work, so this might be wrong..... but my solution would be something like this in real life:

Code:
```typedef char *(*fn)(int) fnptr;
fnptr somefunction(fnptr *);```
Expanding it and getting rid of the typedef...:

Code:
`(char *(*fn)(int)) somefunction((char *(*fn)(int)) *);`
Yeah....

8. why do i get tis error message on typedef. It looks to me everything is fine

Code:
```typedef void (*(*Bloggs)[10])(int **) FTR;
FTR fred(int *, const char *);```
Error message
17 D:\Final year\Distributed Systems\Tutorial1\Prog2.c expected '=', ',', ';', 'asm' or '__attribute__' before 'FTR'
18 D:\Final year\Distributed Systems\Tutorial1\Prog2.c expected '=', ',', ';', 'asm' or '__attribute__' before 'fred'

ssharish

9. You can't typedef an array type, I believe. You would have to break it down further. Perhaps a pointer to a function with int ** as a parameter and returning a void *.

Then you could return an array of function pointers like you would any other.

typedef void *( *foo )( int ** );
foo *bar( int *d, const char *s );

Making a typedef for a function pointer is something to get used to for sure. Notice I only had to name the pointer.

whoops.

10. >You can't typedef an array type, I believe.
Sure you can. You can typedef pretty much anything:
Code:
```#include <stdio.h>

typedef int i10[10];

int main ( void )
{
i10 a;
int i;

for ( i = 0; i < 10; i++ )
a[i] = i;

for ( i = 9; i >= 0; i-- )
printf ( "%d\n", a[i] );

return 0;
}```
>why do i get tis error message on typedef.
Because Bloggs is the name of the typedef, not FTR. Your compiler doesn't know how to parse FTR. Try this instead:
Code:
```typedef void (*(*Bloggs)[10])(int **);
Bloggs fred(int *, const char *);```