Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / native_client_sdk / src / libraries / sdk_util / macros.h
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 #ifndef LIBRARIES_SDK_UTIL_MACROS_H_
6 #define LIBRARIES_SDK_UTIL_MACROS_H_
7
8 /**
9  * A macro to disallow the evil copy constructor and operator= functions
10  * This should be used in the private: declarations for a class.
11  */
12 #define DISALLOW_COPY_AND_ASSIGN(TypeName)      \
13   TypeName(const TypeName&);                    \
14   void operator=(const TypeName&)
15
16 /** returns the size of a member of a struct. */
17 #define MEMBER_SIZE(struct_name, member) sizeof(((struct_name*)0)->member)
18
19 /**
20  * Macros to prevent name mangling of definitions, allowing them to be
21  * referenced from C.
22  */
23 #ifdef __cplusplus
24 # define EXTERN_C_BEGIN  extern "C" {
25 # define EXTERN_C_END    }
26 #else
27 # define EXTERN_C_BEGIN
28 # define EXTERN_C_END
29 #endif  /* __cplusplus */
30
31 /**
32  * Macros to help force linkage of symbols that otherwise would not be
33  * included.
34  *
35  * // In a source file that you want to force linkage (file scope):
36  * FORCE_LINK_THIS(myfilename);
37  *
38  * // In a source file that you are sure will be linked (file scope):
39  * FORCE_LINK_THAT(myfilename)
40  *
41  */
42 #define FORCE_LINK_THIS(x) int force_link_##x = 0;
43 #define FORCE_LINK_THAT(x) \
44   void force_link_function_##x() { \
45     extern int force_link_##x; \
46     force_link_##x = 1; \
47   }
48
49 /**
50  * Macro to error out when a printf-like function is passed incorrect arguments.
51  *
52  * Use like this:
53  * void foo(const char* fmt, ...) PRINTF_LIKE(1, 2);
54  *
55  * The first argument is the location of the fmt string (1-based).
56  * The second argument is the location of the first argument to validate (also
57  *   1-based, but can be zero if the function uses a va_list, like vprintf.)
58  */
59 #if defined(__GNUC__)
60 #define PRINTF_LIKE(a, b) __attribute__ ((format(printf, a, b)))
61 #else
62 #define PRINTF_LIKE(a, b)
63 #endif
64
65 #endif  /* LIBRARIES_SDK_UTIL_MACROS_H_ */