Topic: reinterpret_cast<pointer>(enum)


Author: "cuibo" <cuibo@email.msn.com>
Date: 2000/06/06
Raw View
Is this class or code in template?
Paul Meyerholtz wrote in message <39289035.BCF0D530@ix.netcom.com>...
>I've recently had to do a reinterpret cast on an enum value.  Changing
>the type to a char *.  In this instance, the enum value was stored into
>a byte, pointers are 4 bytes long.
>
>I found out that
>
>reinterpret_cast<char *>(enum)
>
>would not work.  The compiler flagged it as an illegal cast. I needed to
>change the code as follows:
>
>reinterpret_cast<char *>(static_cast<long>(enum))
>
>The question:  Is the compiler correct?  Or should the simple
>reinterpret_cast work.  Should I file a bug report on the compiler?
>
>Paul
>
>---
>[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
>[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
>[              --- Please see the FAQ before posting. ---               ]
>[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]
>



---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: James Kuyper <kuyper@wizard.net>
Date: 2000/05/25
Raw View
Paul Meyerholtz wrote:
>
> I've recently had to do a reinterpret cast on an enum value.  Changing
> the type to a char *.  In this instance, the enum value was stored into
> a byte, pointers are 4 bytes long.
>
> I found out that
>
> reinterpret_cast<char *>(enum)
>
> would not work.  The compiler flagged it as an illegal cast. I needed to
> change the code as follows:
>
> reinterpret_cast<char *>(static_cast<long>(enum))
>
> The question:  Is the compiler correct?  Or should the simple
> reinterpret_cast work.  Should I file a bug report on the compiler?

According to 5.2.10 p5 "A value of ... enumeration type can be
explicitly converted to a pointer."

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Paul Meyerholtz <pholtz@ix.netcom.com>
Date: 2000/05/24
Raw View
I've recently had to do a reinterpret cast on an enum value.  Changing
the type to a char *.  In this instance, the enum value was stored into
a byte, pointers are 4 bytes long.

I found out that

reinterpret_cast<char *>(enum)

would not work.  The compiler flagged it as an illegal cast. I needed to
change the code as follows:

reinterpret_cast<char *>(static_cast<long>(enum))

The question:  Is the compiler correct?  Or should the simple
reinterpret_cast work.  Should I file a bug report on the compiler?

Paul

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]