I've made two functions to 'cast' a 32/64 bit pointer into a double. The code worked when used alone (Just the .h and a .cpp including it) but when using the .h somewhere else (copied into the project directory and then included) ith throws 'already defined' error for all the functions on the .h file when linking.
the source code for the .h file is the following:
#pragma once
#ifndef __FLOATCAST_H
#define __FLOATCAST_H
//A quick and dirty way of casting pointers into doubles and back
//Should work with BOTH 64bit and 32bit pointers
union ptr_u {
double d;
void* p;
};
double ptr2double(void* pv){
ptr_u ptr;
ptr.p = pv;
return (ptr.d);
};
void* double2ptr(double dv){
ptr_u ptr;
ptr.d = dv;
return(ptr.p);
};
#endif
The link says the functions are already defined on a file source file (rather, his .obj) which does not include this one.
Edit: Why would I want a pointer-inside-double? Because I need Lua (5.1) to call-back an object member function.
Edit2: Lua provides a way of storing user data, it seems like the adequate soluton rather than casting the pointer (see comments)