What is?

S

Shraddha

What is this exactly...

int(*(*ptr (int))(void)

First I thought that this is the pointer to function...But I recognize
that the syntax iss quite different...
If we say that the function is taking void parameters i.e. no
parameters then what "(int i)" is doing there...


Please can some one help me out????
 
H

Harald van =?UTF-8?B?RMSzaw==?=

Shraddha said:
What is this exactly...

int(*(*ptr (int))(void)

First I thought that this is the pointer to function...But I recognize
that the syntax iss quite different...
If we say that the function is taking void parameters i.e. no
parameters then what "(int i)" is doing there...


Please can some one help me out????

ptr is a pointer to a function which accepts a single argument of type int.
This function returns a pointer to a function which accepts no arguments
and returns an int. It is more readable when written as

typedef int (*ptr_to_intfunc)(void);
ptr_to_intfunc (*ptr(int));
 
B

bakzam

ptr is a pointer to a function which accepts a single argument of type int.
This function returns a pointer to a function which accepts no arguments
and returns an int. It is more readable when written as

typedef int (*ptr_to_intfunc)(void);
ptr_to_intfunc (*ptr(int));

No, first there is a typo. it should have a respective closing
parenthesis.

int(*(*ptr (int)))(void)

ptr is a function that takes int as an argument and returns a pointer
to a pointer to a function that takes no arguments are returns an
integer.
 
R

regis

Shraddha said:
What is this exactly...

int(*(*ptr (int))(void)

First I thought that this is the pointer to function...But I recognize
that the syntax iss quite different...
If we say that the function is taking void parameters i.e. no
parameters then what "(int i)" is doing there...

Your parentheses are not balanced:
There are three cases to rebalance them:

1) you mean: int(*(*xxx ) (int)) (void) ;
2) you mean: int(*(*yyy (int)) ) (void) ;
3) you mean: int(*(*zzz (int)) (void) );

=====
1) you mean: int(*(*xxx ) (int)) (void) ;
xxx is pointer to function taking parameter int and returning...
a pointer to function taking parameter void and returning int.

static int count= 0;
int dec_count(void) { return count--; }
int inc_count(void) { return count++; }
typedef int (* count_func) (void);
count_func selector(int k) { return k ? inc_count : dec_count; }

you can then make xxx point to function selector:
int(*(*xxx ) (int)) (void)= selector;
or...
count_func (*xxx) (int)= selector;

=====
2) you mean: int(*(*yyy (int)) ) (void) ;

this is the same as:
int (** yyy (int)) (void);

yyy is a function taking parameter int and returning...
pointer to pointer to function taking parameter void and returning int.

int two (void) { return 2; }
int one (void) { return 1; }
typedef int (* func) (void);
func one_bis= one, two_bis= two;

then yyy can be defined as:
int (** yyy (int k)) (void) { return k ? & two_bis : & one_bis; }
or in a more readable way:
func * yyy (int choice) { return k ? & two_bis : & one_bis; }

=====
3) you mean: int(*(*zzz (int)) (void) );
this is the same as
int* (*zzz (int)) (void);

zzz is a function taking parameter int and returning...
pointer to function taking parameter void and returning int*.

int* null (void) { return NULL; }
int* nonnull (void) { static int hell= 666; return & hell; }
typedef int* (* func) (void);

then zzz can be defined as:
int* (*zzz (int)) (void) { return k ? nonnull : null; }
or in a more readable way:
func zzz (int k) { return k ? nonnull : null; }
 
R

regis

regis said:
yyy can be defined as:
int (** yyy (int k)) (void) { return k ? & two_bis : & one_bis; }
or in a more readable way:
func * yyy (int choice) { return k ? & two_bis : & one_bis; }

Here, I meant:
func * yyy (int k) { return k ? & two_bis : & one_bis; }

zzz can be defined as:
int* (*zzz (int)) (void) { return k ? nonnull : null; }
or in a more readable way:
func zzz (int k) { return k ? nonnull : null; }

Here, I meant:
int* (*zzz (int k)) (void) { return k ? nonnull : null; }
 
C

Clever Monkey

Shraddha said:
int(*(*ptr (int))(void)

First I thought that this is the pointer to function...But I recognize
that the syntax iss quite different...
If we say that the function is taking void parameters i.e. no
parameters then what "(int i)" is doing there...
Check out a utility called "cdecl", but first (as suggested else-thread)
you will have to fix the syntax of this line.
 
U

user923005

Check out a utility called "cdecl", but first (as suggested else-thread)
you will have to fix the syntax of this line.
--
clvrmnky <mailto:[email protected]>

Direct replies will be blacklisted. Replace "spamtrap" with my name to
contact me directly.

C:\cdecl>type test.txt
explain int(*(*xxx ) (int)) (void) ;
explain int(*(*yyy (int)) ) (void) ;
explain int(*(*zzz (int)) (void) );


C:\cdecl>cdecl < test.txt
declare xxx as pointer to function (int) returning pointer to function
(void) returning int
declare yyy as function (int) returning pointer to pointer to function
(void) returning int
declare zzz as function (int) returning pointer to function (void)
returning pointer to int
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top