summaryrefslogtreecommitdiff
path: root/src/stdafx.h
diff options
context:
space:
mode:
authorKUDr <KUDr@openttd.org>2007-01-14 21:03:21 +0000
committerKUDr <KUDr@openttd.org>2007-01-14 21:03:21 +0000
commit3439942ab5e4314d793e96259126dd6ee8321937 (patch)
tree503a72c72c0782e2575e32241326c275442bc90d /src/stdafx.h
parent968f748836f1f585badc6eb61b0bcc2f72b1e0c4 (diff)
downloadopenttd-3439942ab5e4314d793e96259126dd6ee8321937.tar.xz
(svn r8131) -Fix (r8125): g++ warning: 'invalid access to non-static data member ‘<class>::<member>’ of NULL object'. It is weird, but renaming the 'offsetof' macro helped.
Diffstat (limited to 'src/stdafx.h')
-rw-r--r--src/stdafx.h12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/stdafx.h b/src/stdafx.h
index c854e4a61..6c6a21ec7 100644
--- a/src/stdafx.h
+++ b/src/stdafx.h
@@ -290,10 +290,18 @@ assert_compile(sizeof(uint8) == 1);
#define lengthof(x) (sizeof(x)/sizeof(x[0]))
#define endof(x) (&x[lengthof(x)])
#define lastof(x) (&x[lengthof(x) - 1])
-#ifndef offsetof
-# define offsetof(s,m) (size_t)&(((s *)0)->m)
+
+#ifdef offsetof
+# undef offsetof
#endif
+#ifndef __cplusplus
+# define offsetof(s,m) (size_t)&(((s *)0)->m)
+#else /* __cplusplus */
+# define cpp_offsetof(s,m) (((size_t)&reinterpret_cast<const volatile char&>((((s*)(char*)8)->m))) - 8)
+# define offsetof(s,m) cpp_offsetof(s, m)
+#endif /* __cplusplus */
+
// take care of some name clashes on macos
#if defined(__APPLE__)