Boost logo

Boost :

From: Robert Ramey (ramey_at_[hidden])
Date: 2003-11-15 00:35:01


Vladimir Prus wrote:

>Robert,
>I'm just trying to find out why void_cast tests fail on gcc 3.3. Could you
>answer two quick questions:

>1. Why void_cast is needed in the first place. It's hard to debug it without
>fully understanding the purpose.

This is vaguely touched upon in the manual. I can be found in the last paragraph of
the section "Pointers to Objects of Derived Classes". For a better illustration of what
it does look for void _downcast in oserializer.hpp where pointers of an abstract base type
are converted to a pointer of the derived type. typeid gives it the most derived type at
run time. Now how do we adjust the pointer from the base type to the correct
derived type ?

void * derived_ptr = static_cast<?>(base_ptr)

since ? isn't known until runtime we're stuck. So void_downcast/void_upcase were
invented to be able to do this. void_cast builds a table before runtime via "hidden"
invocation of void_register(base, derived) in the base_object function.

// if its not a pointer to a more derived type
const void *vp = static_cast<const void *>(&t);
    if(*this_type != *true_type){
        // convert pointer to more derived type
        vp = void_downcast(*this_type, *true_type, &t);
        assert(NULL != vp);
        bos_ptr = basic_oserializer::find(*true_type);
    }

There is an analogous situation in iserializer.hpp

>2. Are all BOOST_CHECK in 'test_void_cast.cpp' are supposed to be completely
>independent from each other and work no matter how I rearrange or comment out
>them?

yes,

The only requirement for the test is that the registration of the base/derived
pairs be left to the end. This emulates the case in the serialization system
where by the serialization code comes before the base/derived pair regstration.
void_cast_register is written so the table is built before main() is invoked.

Robert Ramey


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk