3

I am reading reinterpret_cast documentation at http://en.cppreference.com/w/cpp/language/reinterpret_cast and it says in point 3 that:

A pointer converted to an integer of sufficient size and back to the same pointer type is guaranteed to have its original value, otherwise the resulting pointer cannot be dereferenced safely (the round-trip conversion in the opposite direction is not guaranteed; the same pointer may have multiple integer representations)

So it says that converting an integer to pointer of some type and back to integer not defined. Correct me if I am wrong.

Can you please explain in what cases would this be undefined ? Or why is it undefined?

François Andrieux
  • 28,148
  • 6
  • 56
  • 87
Monku
  • 2,440
  • 4
  • 33
  • 57
  • 1
    FWIW: "Undefined" simply means "The C++ Standard does not define what should happen in this scenario, therefore anything can happen", so you get people talking about your computer launching nukes or opening your garage door or doing other nonsense. – AndyG Mar 13 '17 at 19:10
  • See this SO answer. http://stackoverflow.com/a/29476024/434551. – R Sahu Mar 13 '17 at 19:15
  • 2
    @AndyG the other day my computer opened the garage door thereby exposing my nukes to everyone. All I did was type c / c++ – Bathsheba Mar 13 '17 at 19:23

0 Answers0