Easier way to get hex address String for pointer?

Is there an easy way to get a hex address String (for logging)? Currently, I am using this:

... << String::toHexString((unsigned long)(void*)this) << ...

but that’s a lot of typing. I’m outputting to a stream, and initially just cast the pointer as (unsigned long)(void*), but that gives me a decimal value, so I passed the result of that to String::toHexString(), but I’m just wondering if there is an easier way to stream pointers as hex strings?

If you need that in multiple places or you want to clean up even a single usage of it, just wrap up that in a function? :man_shrugging:

1 Like

I recommend you cast to a pointer_sized_int or pointer_sized_uint instead of an unsigned long; otherwise, you may have issues with 64-bit code.

Matt

1 Like

I took both of your advice, and made a function (which uses the correct pointer size integer). Just seems like it would have been such a common thing to do that there might be a built-in conversion for this. Guess not.