Boost logo

Boost Users :

Subject: Re: [Boost-users] boost::bind and Motif
From: Jeffrey Lee Hellrung, Jr. (jeffrey.hellrung_at_[hidden])
Date: 2012-05-04 14:42:58


On Fri, May 4, 2012 at 6:33 AM, Andrew Holden <aholden_at_[hidden]
> wrote:

> On Thursday, May 03, 2012 2:42 PM, Richard wrote:
> > boost-users_at_[hidden] spake the secret code
> <1D97E025367AFB4A8C528590A3715BF442603A_at_archerysummit2.willamette.charte
> roaksystems.com> thusly:
> >
> >> static void Internal_callback (XtPointer self, XtIntervalId*)
> >> {
> >> reinterpret_cast <AppTimeout*> (self)->callback();
> >
> > I don't know why people always leap to reinterpret_cast<> as their
> > first choice; it's the most dangerous. I'd prefer static_cast<> here.
>
> In this case, the reinterpret_cast is needed because X11 specified that
> your callback *must* take a void pointer. Reinterpret_cast and the old
> c-style cast (which would act as a reinterpret_cast in this case) are
> the only ways I know to convert a void pointer to the correct type. In
> this case, I mitigated the danger by making Internal_callback private
> and ensuring the only place where it is used--the public Schedule
> function--provides a pointer of the correct type.
>

Sorry, drifting off-topic, and I'm not sure what XtPointer is, but based on
your comment above, it seems it is a void pointer, and you can indeed
static_cast a void pointer to any other (object) pointer type (as long as
you don't drop cv qualifiers).

- Jeff



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net