Velocity Reviews > complicated declaration

# complicated declaration

asit
Guest
Posts: n/a

 03-13-2008
Are the following declaration correct ??

int *p// p is a pointer to integer

int *p[]// p is an array of integer pointers

int (*p)[]// p is a pointer to an integer array

int *p()// p is a pointer to function returning

int p(char *)//p is a function which takes a character pointer
as an argument and returns an integer

int *p(char *)// p is a function which takes a character pointer
as an argument and returns the address of an integer(integer pointer)

int (*p)(char *)// p is a pointer to a function which takes a
character pointer
as an argument and returns an integer

---------------------------------------------

int (*p(char*))[]// p is a pointer to a function and takes a character
pointer
as an argument and returns an array of integers

int p(char(*a)[])//p is a function which takes a pointer to a
character array
as an argument and returns an integer

int p(char*[])//p is a function which takes an array of character
pointers
as an argument and returns an integer

int *p(char a[])//p is a function which takes a character array
as an argument and returns an address of an integer(integer pointer)

int p(char (*a)[])//p is a function which takes a pointer to a
character array
as an argument and returns an integer

int *p(char *a[])//p is a function which takes an array of character
pointers
as an argument and returns the address of an integer(integer pointer)

int (*p)(char (*a)[])//p is a pointer to function which takes a
pointer
to a character array as an argument and returns an integer

int *(*p)(char(*a)[])//p is a pointer to function which takes a
pointer
to a character array as an argument and returns the address of an
integer(integer pointer)

--------------------------------------------

int *(*p)(char *a[])//p is a pointer to function which takes an array
of character pointers
as an argument and returns the address of an integer(integer pointer)

int (*p[])(void)//p is an array of pointers to function taking no
argument
and returning an integer

int (*p[])(char a)//p is an array of pointers to function taking a
character argument
and returning an integer

int *(*p[])(char a)//p is an array of pointers to function taking a
character argument
and returning an address of integer(integer pointer)

int *(*p[])(char *a)//p is an array of pointers to function taking a
character array as

argument and returning an address of integer(integer pointer)

WANG Cong
Guest
Posts: n/a

 03-13-2008
On Wed, 12 Mar 2008 23:54:25 -0700，asit wrote：

> Are the following declaration correct ??

Yes, except the below one.

<snip>

>
> int *p()// p is a pointer to function returning address of an
> integer(integer pointer)

This is wrong. p is a function instead of a function pointer.
If you want it to be a pointer, you should:

int (*p)();

And note that it can take *any* arguments, the following statements
are correct.

int (*p)();
int (*q)(int);
int (*r)(void);
p = q;
p = r;

--
Hi, I'm a .signature virus, please copy/paste me to help me spread
all over the world.

John Bode
Guest
Posts: n/a

 03-13-2008
On Mar 13, 1:54 am, asit <(E-Mail Removed)> wrote:
> Are the following declaration correct ??
>

[snip]

> int *p()// p is a pointer to function returning
> address of an integer(integer pointer)
>

Incorrect. p is a function returning a pointer to int. What you're
thinking of is

int *(*p)();

[snip]

> int (*p(char*))[]// p is a pointer to a function and takes a character
> pointer
> as an argument and returns an array of integers
>

Incorrect in that functions may not return array types (or other
function types), although you clearly understand declarator syntax.
You can return a pointer to an array:

int (*(*p(char*)))[];

p is a pointer to a function taking a char* argument and returning a
pointer to an array of int.

[snip remainder]

Ben Bacarisse
Guest
Posts: n/a

 03-13-2008
John Bode <(E-Mail Removed)> writes:

> On Mar 13, 1:54 am, asit <(E-Mail Removed)> wrote:
>> Are the following declaration correct ??

<snip>
>> int (*p(char*))[]// p is a pointer to a function and takes a character
>> pointer
>> as an argument and returns an array of integers
>>

>
> Incorrect in that functions may not return array types (or other
> function types), although you clearly understand declarator syntax.
> You can return a pointer to an array:
>
> int (*(*p(char*)))[];
>
> p is a pointer to a function taking a char* argument and returning a
> pointer to an array of int.

ITYM int (*((*p)(char*)))[];

In general, where the name in next to a "(" it declares a function,
not a pointer to one.

--
Ben.