diff options
-rw-r--r-- | ppapi/c/pp_bool.h | 5 | ||||
-rw-r--r-- | ppapi/c/pp_macros.h | 12 | ||||
-rw-r--r-- | ppapi/c/pp_var.h | 2 |
3 files changed, 19 insertions, 0 deletions
diff --git a/ppapi/c/pp_bool.h b/ppapi/c/pp_bool.h index 44c360e..bbb5e0ea 100644 --- a/ppapi/c/pp_bool.h +++ b/ppapi/c/pp_bool.h @@ -5,6 +5,8 @@ #ifndef PPAPI_C_PP_BOOL_H_ #define PPAPI_C_PP_BOOL_H_ +#include "ppapi/c/pp_macros.h" + /** * @file * Defines the API ... @@ -23,6 +25,9 @@ typedef enum { PP_FALSE = 0, PP_TRUE = 1 } PP_Bool; + +PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_Bool, 4); + /** * @} * End addtogroup PP diff --git a/ppapi/c/pp_macros.h b/ppapi/c/pp_macros.h index e864cc1..ffc48b0 100644 --- a/ppapi/c/pp_macros.h +++ b/ppapi/c/pp_macros.h @@ -37,6 +37,18 @@ # endif #endif +/* This is a compile-time assertion useful for ensuring that a given type is + a given number of bytes wide. The size of the array is designed to be 1 + (which should always be valid) if the enum's size is SIZE, and otherwise the + size of the array will be -1 (which all/most compilers should flag as an + error). This is wrapped inside a struct, because if it is a simple global + we get multiple definition errors at link time. */ +#define PP_COMPILE_ASSERT_SIZE_IN_BYTES(NAME, SIZE) \ +struct _dummy_struct_for_##NAME { \ +char _COMPILE_ASSERT_FAILED_The_type_named_ \ +## NAME ## _is_not_ ## SIZE ## \ +_bytes_wide[(sizeof(NAME) == SIZE) ? 1 : -1]; } + /** * @} * End of addtogroup PP diff --git a/ppapi/c/pp_var.h b/ppapi/c/pp_var.h index 81596d6..fad5db4 100644 --- a/ppapi/c/pp_var.h +++ b/ppapi/c/pp_var.h @@ -27,6 +27,8 @@ typedef enum { PP_VARTYPE_OBJECT } PP_VarType; +PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_VarType, 4); + /** * Do not rely on having a predictable and reproducible * int/double differentiation. |