Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef PTR32_H
- #define PTR32_H
- #include <stdint.h>
- #include "assert.h"
- template <typename T>
- class ptr32
- {
- private:
- uint32_t raw;
- public:
- ptr32() { }
- ptr32(uintptr_t v) {
- if (sizeof(v) > sizeof(uint32_t))
- assert(v <= 0xffffffff);
- raw = v;
- }
- ptr32<T> operator= (T* v) {
- if (sizeof(v) > sizeof(uint32_t))
- assert(v <= (T*)0xffffffff);
- raw = (uint32_t)(uintptr_t)v;
- return *this;
- }
- operator T* () { return (T*)(uintptr_t)raw; }
- template <typename U>
- U cast() { return (U)(uintptr_t)raw; }
- };
- #endif /* PTR32_H */
Advertisement
Add Comment
Please, Sign In to add comment