universal pointer to restricted pointer

R

rz0

Hi,

I have a function that takes a callback function (function pointer of
some type) and a value to be passed to it when it is invoked later. The
prototype looks pretty much like :

int reg(int (*)(void *), void *);

Now, it appears that most of the values (second argument) I want to
register have types of the form T * restrict *, that is, a pointer to
a restricted pointer to some type T. Since there is no implicit
conversion to void *, I have to cast each time I make a call to the
registration function.

I would like to have a different prototype for such cases so the cast
becomes unecessary. If it were const, then using const void * would be
a solution but restrict cannot be applied to void. Is there any elegant
alternative to the problem ?

Thanks
 
A

arun

rz0 said:
Hi,

I have a function that takes a callback function (function pointer of
some type) and a value to be passed to it when it is invoked later. The
prototype looks pretty much like :

int reg(int (*)(void *), void *);

Now, it appears that most of the values (second argument) I want to
register have types of the form T * restrict *, that is, a pointer to
a restricted pointer to some type T. Since there is no implicit
conversion to void *, I have to cast each time I make a call to the
registration function.

I would like to have a different prototype for such cases so the cast
becomes unecessary. If it were const, then using const void * would be
a solution but restrict cannot be applied to void. Is there any elegant
alternative to the problem ?

Thanks

If the second argument is always of same type, why cant you use that
type for the second actual argument ?
Otherwise if it differs in some cases, I think you can make use of
variable length argument lists in this case. I dont know how elegant
this solution is. But it will be useful, since you can avoid casting
the second argument in the call and do it inside your function.

Regards,
arun..
 

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

No members online now.

Forum statistics

Threads
473,815
Messages
2,569,702
Members
45,492
Latest member
juliuscaesar

Latest Threads

Top