Re: typedef with function pointers
- From: Ben Bacarisse <ben.usenet@xxxxxxxxx>
- Date: Sun, 30 Sep 2007 19:31:08 +0100
vardhan <vardhanw@xxxxxxxxx> writes:
On Sep 30, 1:52 pm, Tor Rustad <tor_rus...@xxxxxxxxxxx> wrote:
Googy wrote:
Hi!!
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..
homework-o-meter = 100%
Hint: cdecl
Heres are quick question:
A typical typedef for a data type like a struct goes like:
typedef struct X { ...} XStruct;
where XStruct is now "struct X". Why don't we follow a similar way to
define function pointers?
We can, but the pointers are the problem. For example:
typedef int XFunc(void);
defines XFunc to be a name for the type "function of no parameters
returning int". There is an exact equivalence between this and the
code you posted to typedef a "struct X".
If you want a typdef for a pointer to a "struct X" we just add a star,
because the syntax works:
typedef struct X { ... } *XStructPtr;
but you can't just add a star in front of XFunc above because in that
case the start will be associated with the return type of the
function:
typedef int *XFunc(void);
This is a synonym for "function of no parameters returning a pointer
to int". To alter this association, we need brackets:
typedef int (*XFuncPtr)(void);
Now XFuncPtr is "pointer to function of no parameters returning an
int". Of course. given the first simple typedef, we can use it to
define the second more easily:
typedef int XFunc(void);
typedef XFunc *XFuncPtr;
and many people prefer to do this for complex point to function (and
array) types.
Or is it that the placement of the type
defined follows a similar rule for both these declarations?
I could not understand that. I hope you did not mean what I just said
at great length!
--
Ben.
.
- References:
- typedef with function pointers
- From: Googy
- Re: typedef with function pointers
- From: Tor Rustad
- Re: typedef with function pointers
- From: vardhan
- typedef with function pointers
- Prev by Date: Re: Macro for supplying memset with an unsigned char
- Next by Date: Re: typedef with function pointers
- Previous by thread: Re: typedef with function pointers
- Next by thread: Re: typedef with function pointers
- Index(es):
Relevant Pages
|