[openbeosstorage] Re: [Open-beos-cvs]CVS:current/src/kernel/core/disk_device_managerddm_userland_interface.cpp,1.17,1.18

On 2003-09-28 at 04:03:54 [-0700], Ingo Weinhold wrote:
> 
> On 2003-09-28 at 12:25:25 [+0200], Tyler Dauwalder wrote:
> > On 2003-09-28 at 03:18:59 [-0700], Ingo Weinhold wrote:
> > > 
> > > On 2003-09-27 at 22:10:08 [+0200], Tyler Dauwalder wrote:
> > > > > [...]
> > > > > > @@ -538,11 +554,20 @@
> > > > > >  // _kern_get_disk_device_data
> > > > > >  status_t
> > > > > >  _kern_get_disk_device_data(partition_id id, bool deviceOnly, bool
> > > > > >  shadow,
> > > > > > -                           user_disk_device_data *buffer, size_t
> > > > > > bufferSize,
> > > > > > +                           user_disk_device_data *_buffer, size_t
> > > > > > bufferSize,
> > > > > >                             size_t *neededSize)
> > > > > >  {
> > > > > > -    if (!buffer && bufferSize > 0)
> > > > > > +    if (!_buffer && bufferSize > 0)
> > > > > >          return B_BAD_VALUE;
> > > > > > +
> > > > > > +    // copy in
> > > > > > +    user_disk_device_data *buffer = bufferSize > 0
> > > > > > +                                    ?
> > > > > > reinterpret_cast<user_disk_device_data*>(malloc(bufferSize))
> > > > > 
> > > > > static_cast should be sufficient, BTW. No need for the sledgehammer.
> > > > > ;-)
> > > > 
> > > > I'm not sure I see how reinterpret_cast<> is a sledgehammer.
> > > 
> > > Well, it cast anything to anything else. static_cast only casts between
> > > compatible pointer or reference types and even heeds consts.
> > 
> > Ah, I see; I took sledgehammer to imply it was heavy, a la dynamic_cast<>.
> > At
> > any rate, doesn't reinterpret_cast<> heed consts, as well? I thought only
> > const_cast<> got to muck around with those.
> 
> Oh, you're right. Though, reinterpret_cast is nasty enough, that using two 
> of
> them one can also cast consts away:
> 
>     const char *x = 0;
>     char *y = reinterpret_cast<char*>(reinterpret_cast<int>(x));
> 
> :-)

That's terrible. :-) Good to know, though. :-)

-Tyler

Other related posts: