Don't use variable-length-arrays

This commit is contained in:
Behdad Esfahbod 2010-05-13 13:34:17 -04:00
parent 72071a8afa
commit f679635893
1 changed files with 9 additions and 2 deletions

View File

@ -77,9 +77,14 @@ inline Type& StructAfter(TObject &X)
* Size checking * Size checking
*/ */
/* Check _assertion in a method environment */
#define _DEFINE_SIZE_ASSERTION(_assertion) \ #define _DEFINE_SIZE_ASSERTION(_assertion) \
inline void _size_assertion (void) const \ inline void _size_assertion (void) const \
{ ASSERT_STATIC (_assertion); } { ASSERT_STATIC (_assertion); }
/* Check that _code compiles in a method environment */
#define _DEFINE_COMPILES_ASSERTION(_code) \
inline void _compiles_assertion (void) const \
{ _code; }
#define DEFINE_SIZE_STATIC(size) \ #define DEFINE_SIZE_STATIC(size) \
@ -99,11 +104,13 @@ inline Type& StructAfter(TObject &X)
static const unsigned int min_size = (size) static const unsigned int min_size = (size)
#define DEFINE_SIZE_ARRAY(size, array) \ #define DEFINE_SIZE_ARRAY(size, array) \
_DEFINE_SIZE_ASSERTION (sizeof (*this) == (size) + array[0].static_size); \ _DEFINE_SIZE_ASSERTION (sizeof (*this) == (size) + sizeof (array[0])); \
_DEFINE_COMPILES_ASSERTION ((void) array[0].static_size) \
static const unsigned int min_size = (size) static const unsigned int min_size = (size)
#define DEFINE_SIZE_ARRAY2(size, array1, array2) \ #define DEFINE_SIZE_ARRAY2(size, array1, array2) \
_DEFINE_SIZE_ASSERTION (sizeof (*this) == (size) + this->array1[0].static_size + this->array2[0].static_size); \ _DEFINE_SIZE_ASSERTION (sizeof (*this) == (size) + sizeof (this->array1[0]) + sizeof (this->array2[0])); \
_DEFINE_COMPILES_ASSERTION ((void) array1[0].static_size; (void) array2[0].static_size) \
static const unsigned int min_size = (size) static const unsigned int min_size = (size)