mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-16 00:12:51 +00:00
(svn r19698) -Add: macros to get the size/length of a variable within a class
This commit is contained in:
parent
02363447a6
commit
d058df8828
16
src/stdafx.h
16
src/stdafx.h
@ -371,6 +371,22 @@ assert_compile(sizeof(uint8) == 1);
|
|||||||
#define offsetof(s, m) cpp_offsetof(s, m)
|
#define offsetof(s, m) cpp_offsetof(s, m)
|
||||||
#endif /* offsetof */
|
#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 */
|
/* take care of some name clashes on MacOS */
|
||||||
#if defined(__APPLE__)
|
#if defined(__APPLE__)
|
||||||
|
Loading…
Reference in New Issue
Block a user