$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
From: Zeljko Vrba (zvrba.nospam_at_[hidden])
Date: 2007-06-04 15:30:43
On Mon, Jun 04, 2007 at 08:54:03PM +0200, Ion Gaztañaga wrote:
> 
> I'm a bit puzzled, because it seems odd that the hook is not aligned to 
> 4 bytes even if you have a char between data and the hook. The compiler 
> might be reordering things a bit.
> 
No, the data stored in the pointer-to-member is *not* the "real" offset,
contrary to your assumption :)  When checking in the debugger, the hook
is aligned properly.
>
> Could you check the real distance between klass and hook_? Something like:
> 
The statement (after adding 'klass k' in the local scope of main())
cout << (char*)&k.hook_ - (char*)&k << endl;                                                                                                                                              
prints out 84.
Furthermore, given the following program:
==
#include <boost/intrusive/list.hpp>                                                                                                                                                           
                                                                                                                                                                                              
struct klass {                                                                                                                                                                                
    void *data_klass[10];                                                                                                                                                                     
    boost::intrusive::list_member_hook<> hook_;                                                                                                                                               
                                                                                                                                                                                              
    typedef boost::intrusive::list<                                                                                                                                                           
        boost::intrusive::list_member_hook<>::value_traits<                                                                                                                                   
            klass, &klass::hook_>,                                                                                                                                                            
        false> list;                                                                                                                                                                          
};                                                                                                                                                                                            
                                                                                                                                                                                              
static klass Gd;                                                                                                                                                                              
static klass::list Gl;                                                                                                                                                                        
                                                                                                                                                                                              
int main(void)                                                                                                                                                                                
{                                                                                                                                                                                             
    Gl.push_back(Gd);                                                                                                                                                                         
    return 0;                                                                                                                                                                                 
}                                                                                                                                                                                             
==
I step the execution to list::push_back and its first statement
      node_ptr to_insert = ValueTraits::to_node_ptr(value);                                                                                                                                   
The debugger reports:
(dbx) print -r *to_insert                                                                                                                                                                     
*to_insert = {                                                                                                                                                                                
    node::prev_ = (nil)                                                                                                                                                                       
    node::next_ = (nil)                                                                                                                                                                       
}                                                                                                                                                                                             
(dbx) p to_insert                                                                                                                                                                             
to_insert = 0x8062e2c                                                                                                                                                                         
(dbx) up                                                                                                                                                                                      
Current function is main                                                                                                                                                                      
   19       Gl.push_back(Gd);                                                                                                                                                                 
(dbx) p &Gd                                                                                                                                                                                   
&Gd = 0x8062e2c                                                                                                                                                                               
So, the "to_insert" does not point to the hook address, but to the very
beginning of the structure.
BTW, this is with SunStudio 12: CC: Sun C++ 5.9 SunOS_i386 2007/05/03