Boost logo

Boost :

From: Ullrich Koethe (koethe_at_[hidden])
Date: 2006-10-19 14:34:07


Hi again,

since there was no response to my earlier questions about undefined
behavior, I'd like to bring this up again:

GIL makes extensive use of reinterpret_cast and gil_reinterpret_cast. The
former is, for example, used in code similar to the following:

short * imagedata = new short[3*image_size];
rgb16s_t * rgbdata = (rgb16s_t *)imagedata;

gil_reinterpret_cast is defined as

template <class OutPtr, class In>
OutPtr gil_reinterpret_cast(In * p)
{
     return static_cast<OutPtr>(static_cast<void *>(p));
}

I suspect that undefined behavior results in both cases. IIRC, there is no
guarantee that the memory layout of an rgb array is equal to that of a
corresponding scalar array with three times as many elements (although
this will probably work in practice). Likewise, a static_cast from void *
is only allowed back to the original pointer type, not to a different type.

Can someone more familiar with the fine points of C++ confirm these
suspicions? If they are true, I think the issue should be resolved before
inclusion into boost.

Regards
Ulli

-- 
  ________________________________________________________________
|                                                                |
| Ullrich Koethe  Universitaet Hamburg / University of Hamburg   |
|                 FB Informatik        / Dept. of Informatics    |
|                 AB Kognitive Systeme / Cognitive Systems Group |
|                                                                |
| Phone: +49 (0)40 42883-2573                Vogt-Koelln-Str. 30 |
| Fax:   +49 (0)40 42883-2572                D - 22527 Hamburg   |
| Email: u.koethe_at_[hidden]               Germany             |
|        koethe_at_[hidden]                        |
| WWW:   http://kogs-www.informatik.uni-hamburg.de/~koethe/      |
|________________________________________________________________|

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