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.
6 /* From pp_macros.idl modified Thu Feb 19 13:24:05 2015. */
8 #ifndef PPAPI_C_PP_MACROS_H_
9 #define PPAPI_C_PP_MACROS_H_
12 #define PPAPI_RELEASE 43
16 * Defines the common macros such as assert, inline, ...
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
37 #if defined(__cplusplus)
38 /* The inline keyword is part of C++ and guarantees we won't get multiple
41 # define PP_INLINE inline
43 # if defined(_MSC_VER)
44 # define PP_INLINE static __forceinline
46 # define PP_INLINE static __inline__
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.
57 NAME is the name of the type without any spaces or the struct or enum
60 CTYPENAME is the typename required by C. I.e., for a struct or enum, the
61 appropriate keyword must be included.
63 SIZE is the expected size in bytes.
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]; }
71 /* PP_COMPILE_ASSERT_SIZE_IN_BYTES is for typenames that contain no spaces.
73 PP_COMPILE_ASSERT_SIZE_IN_BYTES(int, 4);
74 typedef struct { int a; } Foo;
75 PP_COMPILE_ASSERT_SIZE_IN_BYTES(Foo, 4);
77 #define PP_COMPILE_ASSERT_SIZE_IN_BYTES(NAME, SIZE) \
78 PP_COMPILE_ASSERT_SIZE_IN_BYTES_IMPL(NAME, NAME, SIZE)
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.
83 struct Foo { int a; };
84 PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(Foo, 4);
86 #define PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(NAME, SIZE) \
87 PP_COMPILE_ASSERT_SIZE_IN_BYTES_IMPL(NAME, struct NAME, SIZE)
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.
92 enum Bar { A = 0, B = 1 };
93 PP_COMPILE_ASSERT_ENUM_SIZE_IN_BYTES(Foo, 4);
95 #define PP_COMPILE_ASSERT_ENUM_SIZE_IN_BYTES(NAME, SIZE) \
96 PP_COMPILE_ASSERT_SIZE_IN_BYTES_IMPL(NAME, enum NAME, SIZE)
100 * End of addtogroup PP
103 #endif /* PPAPI_C_PP_MACROS_H_ */