summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2010-04-23 14:56:14 +0000
committerrubidium <rubidium@openttd.org>2010-04-23 14:56:14 +0000
commitf642c01fb4ab5ab13d2fcb9d6d255cdb60232a7a (patch)
treec5c91e2024190bde323881405890f5ccf0c8a8ef
parent532ac6bd670ab586cfe8778ea9b009f1201abfb5 (diff)
downloadopenttd-f642c01fb4ab5ab13d2fcb9d6d255cdb60232a7a.tar.xz
(svn r19698) -Add: macros to get the size/length of a variable within a class
-rw-r--r--src/stdafx.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/stdafx.h b/src/stdafx.h
index ccda37439..9777e1fa9 100644
--- a/src/stdafx.h
+++ b/src/stdafx.h
@@ -371,6 +371,22 @@ assert_compile(sizeof(uint8) == 1);
#define offsetof(s, m) cpp_offsetof(s, m)
#endif /* offsetof */
+/**
+ * Gets the size of a variable within a class.
+ * @param base The class the variable is in.
+ * @param variable The variable to get the size of.
+ * @return the size of the variable
+ */
+#define cpp_sizeof(base, variable) (sizeof(((base*)8)->variable))
+
+/**
+ * Gets the length of an array variable within a class.
+ * @param base The class the variable is in.
+ * @param variable The array variable to get the size of.
+ * @return the length of the array
+ */
+#define cpp_lengthof(base, variable) (cpp_sizeof(base, variable) / cpp_sizeof(base, variable[0]))
+
/* take care of some name clashes on MacOS */
#if defined(__APPLE__)