Casting this pointer to a number
Hello,
I'd like to provide a function with an unique identifier:
void f(size_t UniqueId);
This function is going to be called from within class member functions
like that:
class a {
a() { f((size_t)this); }
};
Right now the old style cast works. The question is how do I make
conversion using numeric_cast? If I use:
f(boost::numeric_cast
On Sun, Jan 13, 2008 at 08:40:51AM -0600, sj@sjcomp.com wrote:
I'd like to provide a function with an unique identifier:
Why? What is it going to do with the ID? Why not make the ID a void* pointer? And what semantics does this "unique identification" have? Once an object is deleted, another new'd object may get its address; I can hardly qualify that as "unique ID".
I guess another question is: should I bother replacing this old-style cast, maybe there is a better way to approach this situation in general?
reinterpret_cast. although, that's long and painful to type at every function
invocation (so is the old-style cast), so I'd redefine f() as
void f(void *pv)
{
size_t uid = reinterpret_cast
sj@sjcomp.com wrote:
Hello,
I'd like to provide a function with an unique identifier: void f(size_t UniqueId);
Why not generate a GUID as a unique identifier. I know there is functionality for that under Windows and I highly suspect there is functionality for generating a GUID under Linux and Mac.
Edward Diener wrote:
sj@sjcomp.com wrote:
Hello,
I'd like to provide a function with an unique identifier: void f(size_t UniqueId);
Why not generate a GUID as a unique identifier. I know there is functionality for that under Windows and I highly suspect there is functionality for generating a GUID under Linux and Mac.
Or boost.GUID -- provisionally accepted library. GUID v7 in the vault I believe is the latest version: http://www.boost-consulting.com/vault/ Jeff
participants (4)
-
Edward Diener
-
Jeff Garland
-
sj@sjcomp.com
-
Zeljko Vrba