Boost logo

Boost :

From: Matt Doyle (mdoyle_at_[hidden])
Date: 2006-10-19 16:04:19


Hi Ulli,

Section 5.2.10-3 states that this usage is implementation defined, i.e.
not portable.

That said, if we refer to Sutter[2005] section 92. After he finishes
with how bad it is to lie to the compiler he recommends that if it's
absolutely necessary it should be done via a void pointer. Given that
MHO would be that if the cast really is unavoidable then
gil_reinterpret_cast is the correct way to do it (by the book).

As for your other example -> rgb16s_t * rgbdata = (rgb16s_t *)imagedata;

That's not even C++ is it :-)

Matt

> [mailto:boost-bounces_at_[hidden]] On Behalf Of Ullrich Koethe
> 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/ |
> |________________________________________________________________|
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>

Scanned by McAfee GroupShield {X3BTB534}


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