1 /* Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 * Use of this source code is governed by a BSD-style license that can be 3 * found in the LICENSE file. 4 */ 5 6 /* From pp_macros.idl modified Fri Jun 6 18:08:58 2014. */ 7 8 #ifndef PPAPI_C_PP_MACROS_H_ 9 #define PPAPI_C_PP_MACROS_H_ 10 11 12 #define PPAPI_RELEASE 39 13 14 /** 15 * @file 16 * Defines the common macros such as assert, inline, ... 17 */ 18 19 20 21 /* 22 * @addtogroup PP 23 * @{ 24 */ 25 26 /* Use PP_INLINE to tell the compiler to inline functions. The main purpose of 27 * inline functions in ppapi is to allow us to define convenience functions in 28 * the ppapi header files, without requiring clients or implementers to link a 29 * PPAPI C library. The "inline" keyword is not supported by pre-C99 C 30 * compilers (such as MS Visual Studio 2008 and older versions of GCC). MSVS 31 * supports __forceinline and GCC supports __inline__. Use of the static 32 * keyword ensures (in C) that the function is not compiled on its own, which 33 * could cause multiple definition errors. 34 * http://msdn.microsoft.com/en-us/library/z8y1yy88.aspx 35 * http://gcc.gnu.org/onlinedocs/gcc/Inline.html 36 */ 37 #if defined(__cplusplus) 38 /* The inline keyword is part of C++ and guarantees we won't get multiple 39 * definition errors. 40 */ 41 # define PP_INLINE inline 42 #else 43 # if defined(_MSC_VER) 44 # define PP_INLINE static __forceinline 45 # else 46 # define PP_INLINE static __inline__ 47 # endif 48 #endif 49 50 /* This is a compile-time assertion useful for ensuring that a given type is 51 a given number of bytes wide. The size of the array is designed to be 1 52 (which should always be valid) if the enum's size is SIZE, and otherwise the 53 size of the array will be -1 (which all/most compilers should flag as an 54 error). This is wrapped inside a struct, because if it is a simple global 55 we get multiple definition errors at link time. 56 57 NAME is the name of the type without any spaces or the struct or enum 58 keywords. 59 60 CTYPENAME is the typename required by C. I.e., for a struct or enum, the 61 appropriate keyword must be included. 62 63 SIZE is the expected size in bytes. 64 */ 65 #define PP_COMPILE_ASSERT_SIZE_IN_BYTES_IMPL(NAME, CTYPENAME, SIZE) \ 66 struct PP_Dummy_Struct_For_##NAME { \ 67 char _COMPILE_ASSERT_FAILED_The_type_named_ \ 68 ## NAME ## _is_not_ ## SIZE ## \ 69 _bytes_wide[(sizeof(CTYPENAME) == SIZE) ? 1 : -1]; } 70 71 /* PP_COMPILE_ASSERT_SIZE_IN_BYTES is for typenames that contain no spaces. 72 E.g.: 73 PP_COMPILE_ASSERT_SIZE_IN_BYTES(int, 4); 74 typedef struct { int a; } Foo; 75 PP_COMPILE_ASSERT_SIZE_IN_BYTES(Foo, 4); 76 */ 77 #define PP_COMPILE_ASSERT_SIZE_IN_BYTES(NAME, SIZE) \ 78 PP_COMPILE_ASSERT_SIZE_IN_BYTES_IMPL(NAME, NAME, SIZE) 79 80 /* PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES is for typenames that contain 'struct' 81 in C. That is, struct names that are not typedefs. 82 E.g.: 83 struct Foo { int a; }; 84 PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(Foo, 4); 85 */ 86 #define PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(NAME, SIZE) \ 87 PP_COMPILE_ASSERT_SIZE_IN_BYTES_IMPL(NAME, struct NAME, SIZE) 88 89 /* PP_COMPILE_ASSERT_ENUM_SIZE_IN_BYTES is for typenames that contain 'enum' 90 in C. That is, enum names that are not typedefs. 91 E.g.: 92 enum Bar { A = 0, B = 1 }; 93 PP_COMPILE_ASSERT_ENUM_SIZE_IN_BYTES(Foo, 4); 94 */ 95 #define PP_COMPILE_ASSERT_ENUM_SIZE_IN_BYTES(NAME, SIZE) \ 96 PP_COMPILE_ASSERT_SIZE_IN_BYTES_IMPL(NAME, enum NAME, SIZE) 97 98 /** 99 * @} 100 * End of addtogroup PP 101 */ 102 103 #endif /* PPAPI_C_PP_MACROS_H_ */ 104 105