[mythtv] Casts revisited: reinterpret_cast<>, dynamic_cast<>
Daniel Thor Kristjansson
danielk at mrl.nyu.edu
Fri Oct 22 14:53:19 UTC 2004
I know we discussed const_cast<> and static_cast<> earlier. For backward
compatiblity with gcc 2.x it was decided we should just use plain old C
casts. And I've been dutifully converting those.
However, I'm a little hesitant to change reinterpret_cast<> casts to C
style casts. These are often the source of problems, especially when
converting to different platform with different endianness or a with a
larger integer size. I've added this bit of code to mythcontext.h
#if (__GNUC__ > 2)
#define REINTERPRET_CAST(CAST_TYPE, THING_TO_CAST) reinterpret_cast<CAST_TYPE>(THING_TO_CAST)
#else
#define REINTERPRET_CAST(CAST_TYPE, THING_TO_CAST) *((CAST_TYPE*)(&(THING_TO_CAST)))
#endif
And, replaced my reinterpret_cast<>'s appropriately. I'm wondering if
this seems reasonable to other devs? Also, I'm not using any
dynamic_casts but it occured to me that these could be a problem, since
there is no C equivalent. A google revealed that gcc 2.9.x supports
them, but it uses some wacky string search so they are extremely slow.
Also, I know reinterpret_cast is supported by gcc 2.9.2, is there an
exact version of gcc 2.9.x are we targetting?
-- Daniel
More information about the mythtv-dev
mailing list