
on Fri Nov 02 2007, "Peter Dimov" <pdimov-AT-pdimov.com> wrote:
Boris Gubenko:
I think the correct change to silence the type conversion error is
char * first = static_cast<char *>(static_cast<void *>(const_cast<long*>(& l)));
I'm not sure my change is incorrect. In terms of style, I think that your change is better.
Dave's insistence that we have to obfuscate our reinterpret_casts is well known and a very strict reading of the standard is on his side _in this specific case_, but I personally don't find his style better at all.
Me neither. But that's the way it is. BTW, when I asked this question of the standard committee's core working group, the response was a kind of stunned surprise that anyone would even ask, and aside from one person, they all thought it was obviously true that static_cast-ing through void was the only correct thing to do.
(A reinterpret_cast<char*>( p ) is indirectly required to work when p is a pointer to a class type,
Where does the standard say that, and what do you mean by "work?" As far as I know the only things that reinterpret_cast is required to work for are round-trip pointer conversions and -- if a suitable integer type exists -- some kind of conversion of pointers into integer types.
but it's possible in theory for a sufficiently mischievous compiler to break it for long*. I know of no such compiler, present or future, of course.)
And most probably won't, because reinterpret_cast is so widely used with the assumption it does what everyone wants. However, we might want Boost code to pass cleanly through code verification tools, for example. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com