Proper way of casting pointer types

For convertible pointers to fundamental types both casts have the same meaning; so you are correct that static_cast is okay.

When converting between some pointer types, it’s possible that the specific memory address held in the pointer needs to change.

That’s where the two casts differ. static_cast will make the appropriate adjustment. reinterpret_cast will not.

For that reason, it’s a good general rule to static_cast between pointer types unless you know that reinterpret_cast is desired.

Leave a Comment