summaryrefslogtreecommitdiff
path: root/src/stdafx.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/stdafx.h')
-rw-r--r--src/stdafx.h22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/stdafx.h b/src/stdafx.h
index 5ca14d082..34da8f501 100644
--- a/src/stdafx.h
+++ b/src/stdafx.h
@@ -305,8 +305,30 @@ assert_compile(sizeof(uint32) == 4);
assert_compile(sizeof(uint16) == 2);
assert_compile(sizeof(uint8) == 1);
+/**
+ * Return the length of an fixed size array.
+ * Unlike sizeof this function returns the number of elements
+ * of the given type.
+ *
+ * @param x The pointer to the first element of the array
+ * @return The number of elements
+ */
#define lengthof(x) (sizeof(x) / sizeof(x[0]))
+
+/**
+ * Get the end element of an fixed size array.
+ *
+ * @param x The pointer to the first element of the array
+ * @return The pointer past to the last element of the array
+ */
#define endof(x) (&x[lengthof(x)])
+
+/**
+ * Get the last element of an fixed size array.
+ *
+ * @param x The pointer to the first element of the array
+ * @return The pointer to the last element of the array
+ */
#define lastof(x) (&x[lengthof(x) - 1])
#define cpp_offsetof(s, m) (((size_t)&reinterpret_cast<const volatile char&>((((s*)(char*)8)->m))) - 8)