c++ - How to convert pointer value obtained via reference operator to string? -
i beginner in c++. working on project required trace memory address. unfortunately, tracing function has following prototype declaration:
void trc(uint8_t, uint8_t, uint8_t, uint64_t, uint64_t, uint64_t, uint64_t, uint64_t, uint64_t, const char*)
now options available me are:
convert memory address (pointer value)
uint64_t
type. i've read somewhere not recommended, pointer value returned reference operator platform dependent , conversion of pointer integer may return wrong value.convert memory address string , pass via last parameter. in python easy had
str()
function. have similar in c++ too?
please let me know if inferring wrong in approach/understanding here.
you use streams convert if not need fast code.
#include <sstream> #include <iomanip> ... std::ostringstream os; os << std::hex << static_cast<void*>(my_pointer); trc(..., os.str().c_str());
Comments
Post a Comment