Re: typedef with function pointers
- From: Googy <cool.gaurav.ignition@xxxxxxxxx>
- Date: Mon, 01 Oct 2007 09:02:29 -0700
On Sep 30, 11:32 pm, Martin Wells <war...@xxxxxxxxxx> wrote:
Googy:
Can any one explain me the meaning of following notations clearly :
1. typedef char(*(*frpapfrc())[])();
frpapfrc f;
2. typedef int (*(arr2d_ptr)())[3][4];
arr2d_ptr p;
3. typedef int (*(*(*ptr2d_fptr)())[10])();
ptr2d_fptr q;
4. typedef char (*(*arr_fptr[3])())[10];
arr_fptr x;
5. typedef float *(*(*(*ptr_fptr)())[10])();
ptr_fptr y;
What are f,p,q,x,y?? and how?
Please don't just answer what they are explain then clearly..
Thanks in advance...
Given this looks like a homework question, I'll explain how it works
rather than giving you the answer.
First off, typedef has the same syntax as defining variables. For
instance:
int arr[5];
The above defines an array called "arr" with five int elements.
typedef int arr[5];
The above declares a type called "arr" which is an array of five int
elements.
If you're trying to break a complicated declaration down, then start
with the name. I'm not familiar with C99, so I'm going to change the
first declaration a little for it to be C89:
typedef char(*(*frpapfrc(void))[5])(void);
The stuff right beside the name tells you that firstly:
1: It's a function that takes no arguments
2: That returns a pointer
Now take that stuff out and you're left with:
typedef char(*frpapfrc[5])(void);
This tells us that:
3: It's an array of five elements
4: Each element is a pointer
Again, strip that stuff out:
typedef char frpapfrc (void);
5: This is a function with no parameters that returns a char.
Now just put them in order:
A function that takes no arguments, and returns a pointer to an array
of five pointers to functions which take no arguments and which return
a char.
You can test it out as follows:
typedef char(*(*frpapfrc(void))[5])(void);
typedef char A(void);
typedef A *B[5];
typedef B *C;
typedef C D(void);
int main(void)
{
D *p1 = 0;
frpapfrc *p2 = p1; /* Hopefully we don't get a type mis-match */
return 0;
}
Martin
Thanks Martin it was very explanatory and i was able to solve the
problems further, actually i was reading the topic of function
pointers and came across these difficulties...Thanks buddy!!
.
- Prev by Date: Re: A byte can be greater than 8 bits?
- Next by Date: Re: "#pragma once"
- Previous by thread: Re: typedef with function pointers
- Next by thread: Re: typedef with function pointers
- Index(es):
Relevant Pages
|