summaryrefslogtreecommitdiff
path: root/src/common/cbasetypes.h
diff options
context:
space:
mode:
authorflaviojs <flaviojs@54d463be-8e91-2dee-dedb-b68131a5f0ec>2011-09-08 19:47:26 +0000
committerflaviojs <flaviojs@54d463be-8e91-2dee-dedb-b68131a5f0ec>2011-09-08 19:47:26 +0000
commit6fc804e12ad7db569e82229cc11a361066cec682 (patch)
treeddfdf820c20e373e6666b6ae4428099702b47744 /src/common/cbasetypes.h
parent49a1de65bf592bbfe194a06b2b4c41f9865ea8b3 (diff)
downloadhercules-6fc804e12ad7db569e82229cc11a361066cec682.tar.gz
hercules-6fc804e12ad7db569e82229cc11a361066cec682.tar.bz2
hercules-6fc804e12ad7db569e82229cc11a361066cec682.tar.xz
hercules-6fc804e12ad7db569e82229cc11a361066cec682.zip
* Fix C++ compilation issues.
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@14955 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/common/cbasetypes.h')
-rw-r--r--src/common/cbasetypes.h29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/common/cbasetypes.h b/src/common/cbasetypes.h
index 27420edbf..58acad2c7 100644
--- a/src/common/cbasetypes.h
+++ b/src/common/cbasetypes.h
@@ -77,6 +77,12 @@
// portable printf/scanf format macros and integer definitions
// NOTE: Visual C++ uses <inttypes.h> and <stdint.h> provided in /3rdparty
//////////////////////////////////////////////////////////////////////////
+#ifdef __cplusplus
+#define __STDC_CONSTANT_MACROS
+#define __STDC_FORMAT_MACROS
+#define __STDC_LIMIT_MACROS
+#endif
+
#include <inttypes.h>
#include <stdint.h>
#include <limits.h>
@@ -326,4 +332,27 @@ typedef char bool;
#endif
#endif
+
+//////////////////////////////////////////////////////////////////////////
+// Set a pointer variable to a pointer value.
+#ifdef __cplusplus
+template <typename T1, typename T2>
+void SET_POINTER(T1*&var, T2* p)
+{
+ var = static_cast<T1*>(p);
+}
+template <typename T1, typename T2>
+void SET_FUNCPOINTER(T1& var, T2 p)
+{
+ char ASSERT_POINTERSIZE[sizeof(T1) == sizeof(void*) && sizeof(T2) == sizeof(void*)?1:-1];// 1 if true, -1 if false
+ union{ T1 out; T2 in; } tmp;// /!\ WARNING casting a pointer to a function pointer is against the C++ standard
+ tmp.in = p;
+ var = tmp.out;
+}
+#else
+#define SET_POINTER(var,p) (var) = (p)
+#define SET_FUNCPOINTER(var,p) (var) = (p)
+#endif
+
+
#endif /* _CBASETYPES_H_ */