universal pointer to restricted pointer

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • rz0

    universal pointer to restricted pointer

    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
  • arun

    #2
    Re: universal pointer to restricted pointer

    rz0 wrote:[color=blue]
    > 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[/color]

    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..

    Comment

    Working...