vardhan said:
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? Or is it that the placement of the type
defined follows a similar rule for both these declarations?
Forget about the typedef for a moment, and recall C's
practice that "declaration mimics use." When you write
`int x;' you say "x is an int." When you write `int *x;'
you say "*x is an int, hence x is a pointer to int." When
you write `int x[42];' you say "x[index] is an int, hence
x is an array of int. The position of x with respect to
the other elements of the declaration depends on the way
x would be used in an expression: The type comes first,
followed by a sort of "expression template" involving the
identifier that's being declared.
When you write `int f(double x);' you say "f(42.0) is
an int, hence f is a function taking a double and returning
an int." When you write `int (*f)(double x);' you say
"(*f)(42.0) is an int, hence f is a pointer to a function
taking a double and returning an int." Again, the position
of f with respect to the other elements of the declaration
is the position f would have in an actual expression.
Now re-insert the typedef. Syntactically, this is just
like inserting static or extern or register or auto, and does
not affect what goes on in the rest of the declaration. The
others specify where the new identifier's object is to be
stored; typedef says "It's not really an object at all, but
an alias for the type that the object would have had if the
typedef keyword hadn't been there."
int x; /* x is an int; make one */
extern int x; /* x is an int residing elsewhere */
typedef int x; /* x is an alias for int */
int (*f)(double); /* f is a function ptr; make one */
extern int (*f)(double); /* f is a function ptr elsewhere */
typedef int (*f)(double); /* f is an alias for function ptr */