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:

  1. 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.

  2. 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

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -