MySQL  8.0.16
Source Code Documentation
my_macros.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License, version 2.0,
6  as published by the Free Software Foundation.
7 
8  This program is also distributed with certain software (including
9  but not limited to OpenSSL) that is licensed under separate terms,
10  as designated in a particular file or component or in included license
11  documentation. The authors of MySQL hereby grant you an additional
12  permission to link the program and your derivative works with the
13  separately licensed software that they have included with MySQL.
14 
15  This program is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License, version 2.0, for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with this program; if not, write to the Free Software
22  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23 
24 #ifndef MY_MACROS_INCLUDED
25 #define MY_MACROS_INCLUDED
26 
27 /**
28  @file include/my_macros.h
29  Some common macros. Note that some of these should probably be replaced
30  with code from <algorithm> or similar.
31 */
32 
33 #ifndef MYSQL_ABI_CHECK
34 #include <stddef.h>
35 #endif
36 
37 /* Macros to make switching between C and C++ mode easier */
38 #ifdef __cplusplus
39 #define C_MODE_START extern "C" {
40 #define C_MODE_END }
41 #else
42 #define C_MODE_START
43 #define C_MODE_END
44 #endif
45 
46 /* Make it easier to add conditional code in _expressions_ */
47 #ifdef _WIN32
48 #define IF_WIN(A, B) A
49 #else
50 #define IF_WIN(A, B) B
51 #endif
52 
53 /*
54  Two levels of macros are needed to stringify the
55  result of expansion of a macro argument.
56 */
57 #define QUOTE_ARG(x) #x /* Quote argument (before cpp) */
58 #define STRINGIFY_ARG(x) QUOTE_ARG(x) /* Quote argument, after cpp */
59 
60 #define MY_TEST(a) ((a) ? 1 : 0)
61 #define MY_MAX(a, b) ((a) > (b) ? (a) : (b))
62 #define MY_MIN(a, b) ((a) < (b) ? (a) : (b))
63 #define set_if_bigger(a, b) \
64  do { \
65  if ((a) < (b)) (a) = (b); \
66  } while (0)
67 #define set_if_smaller(a, b) \
68  do { \
69  if ((a) > (b)) (a) = (b); \
70  } while (0)
71 #define test_all_bits(a, b) (((a) & (b)) == (b))
72 
73 /* Bug in developerstudio: use the C version */
74 #if defined(__cplusplus) && !defined(__SUNPRO_CC)
75 
76 template <class T, size_t N>
77 constexpr size_t array_elements(T (&)[N]) noexcept {
78  return N;
79 }
80 
81 #else
82 
83 // Less type-safe version that e.g. allows sending in pointers
84 // or STL containers without an error.
85 #define array_elements(A) ((size_t)(sizeof(A) / sizeof(A[0])))
86 
87 #endif
88 
89 #endif // MY_MACROS_INCLUDED
std::atomic< size_t > N
Definition: ut0counter.h:227
constexpr size_t array_elements(T(&)[N]) noexcept
Definition: my_macros.h:77