Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

statement in boost lib, (void)p; what does it mean?

I came across following piece of code in Boost Library for offset_ptr. under boost/interprocess/offset_ptr.hpp

typedef PointedType *                     pointer;
...
    //!Constructor from other pointer.
    //!Never throws.
    template <class T>
    offset_ptr(T *ptr) 
    {  pointer p (ptr);  (void)p; this->set_offset(p); }

I wonder what does a statement (void)p; does?

like image 930
RLT Avatar asked Nov 14 '22 20:11

RLT


1 Answers

One way to find out is to put a break point on that line of code and step through to find out what it does. You can even reformat the code to allow you to set the break point on that particular statement (there's no law against editing these files - just don't change the actual code).

However, my guess is that the pointer type is using some form of lazy evaluation, the emulated cast operators call a set_offset method so maybe the this->set_offset(p) requires p to have a valid offset set up and doing the (void)p just forces it to happen.

like image 144
Skizz Avatar answered Dec 19 '22 01:12

Skizz