From 6fc804e12ad7db569e82229cc11a361066cec682 Mon Sep 17 00:00:00 2001 From: flaviojs Date: Thu, 8 Sep 2011 19:47:26 +0000 Subject: * Fix C++ compilation issues. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@14955 54d463be-8e91-2dee-dedb-b68131a5f0ec --- src/common/cbasetypes.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src/common/cbasetypes.h') 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 and provided in /3rdparty ////////////////////////////////////////////////////////////////////////// +#ifdef __cplusplus +#define __STDC_CONSTANT_MACROS +#define __STDC_FORMAT_MACROS +#define __STDC_LIMIT_MACROS +#endif + #include #include #include @@ -326,4 +332,27 @@ typedef char bool; #endif #endif + +////////////////////////////////////////////////////////////////////////// +// Set a pointer variable to a pointer value. +#ifdef __cplusplus +template +void SET_POINTER(T1*&var, T2* p) +{ + var = static_cast(p); +} +template +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_ */ -- cgit v1.2.3-70-g09d2