2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2004, The GROMACS development team.
6 * Copyright (c) 2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
7 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
8 * and including many others, as listed in the AUTHORS file in the
9 * top-level source directory and at http://www.gromacs.org.
11 * GROMACS is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public License
13 * as published by the Free Software Foundation; either version 2.1
14 * of the License, or (at your option) any later version.
16 * GROMACS is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with GROMACS; if not, see
23 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
24 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 * If you want to redistribute modifications to GROMACS, please
27 * consider that scientific software is very special. Version
28 * control is crucial - bugs must be traceable. We will be happy to
29 * consider code for inclusion in the official distribution, but
30 * derived work must not be called official GROMACS. Details are found
31 * in the README & COPYING files - if they are missing, get the
32 * official version at http://www.gromacs.org.
34 * To help us fund GROMACS development, we humbly ask that you cite
35 * the research papers on the package. Check out http://www.gromacs.org.
39 * Basic types and macros used throughout \Gromacs.
42 * \ingroup module_utility
44 #ifndef GMX_UTILITY_BASEDEFINITIONS_H
45 #define GMX_UTILITY_BASEDEFINITIONS_H
52 #if defined __cplusplus
59 typedef bool gmx_bool;
62 /** False value for ::gmx_bool. */
66 /** True value for ::gmx_bool. */
69 /** Number of gmx_bool values. */
72 #if defined __cplusplus
75 /*! \brief Integer type for indexing into arrays or vectors
79 using index = std::ptrdiff_t;
83 /*! \name Fixed-width integer types
85 * These types and macros provide the equivalent of 32- and 64-bit integer
86 * types from C99 headers `stdint.h` and `inttypes.h`. These headers are also
87 * there in C++11. The types and macros from here should be used instead of
90 * (MSVC 2015 still doesn't support the format strings.)
93 typedef int32_t gmx_int32_t;
94 typedef int64_t gmx_int64_t;
95 typedef uint32_t gmx_uint32_t;
96 typedef uint64_t gmx_uint64_t;
99 #define GMX_PRId32 "I32d"
100 #define GMX_SCNd32 "I32d"
102 #define GMX_PRId64 "I64d"
103 #define GMX_SCNd64 "I64d"
105 #define GMX_PRIu32 "I32u"
106 #define GMX_SCNu32 "I32u"
108 #define GMX_PRIu64 "I64u"
109 #define GMX_SCNu64 "I64u"
111 #define GMX_PRId32 PRId32
112 #define GMX_SCNd32 SCNd32
114 #define GMX_PRId64 PRId64
115 #define GMX_SCNd64 SCNd64
117 #define GMX_PRIu32 PRIu32
118 #define GMX_SCNu32 SCNu32
120 #define GMX_PRIu64 PRIu64
121 #define GMX_SCNu64 SCNu64
124 #define GMX_INT32_MAX INT32_MAX
125 #define GMX_INT32_MIN INT32_MIN
127 #define GMX_INT64_MAX INT64_MAX
128 #define GMX_INT64_MIN INT64_MIN
130 #define GMX_UINT32_MAX UINT32_MAX
131 #define GMX_UINT32_MIN UINT32_MIN
133 #define GMX_UINT64_MAX UINT64_MAX
134 #define GMX_UINT64_MIN UINT64_MIN
137 /* ICC, GCC, MSVC, Pathscale, PGI, XLC support __restrict.
138 * Any other compiler can be added here. */
140 * Keyword to use in instead of C99 `restrict`.
142 * We cannot use `restrict` because it is only in C99, but not in C++.
143 * This macro should instead be used to allow easily supporting different
146 #define gmx_restrict __restrict
148 /*! \def GMX_CXX11_COMPILATION
150 * Defined to 1 when compiling as C++11.
152 * While \Gromacs only supports C++11 compilation, there are some parts of the
153 * code that are compiled with other tools than the actual C++ compiler, and
154 * these may not support C++11. Most notable such case is all of CUDA code
155 * (with CUDA versions older than 6.5), but other types of kernels might also
156 * have similar limitations in the future.
158 * The define is intended for conditional compilation in low-level headers that
159 * need to support inclusion from such non-C++11 files, but get significant
160 * benefit (e.g., for correctness checking or more convenient use) from C++11.
161 * It should only be used for features that do not influence the ABI of the
162 * header; e.g., static_asserts or additional helper methods.
164 #if defined __cplusplus && __cplusplus >= 201103L
165 # define GMX_CXX11_COMPILATION 1
167 # define GMX_CXX11_COMPILATION 0
172 * Attribute to suppress compiler warnings about unused function parameters.
174 * This attribute suppresses compiler warnings about unused function arguments
175 * by marking them as possibly unused. Some arguments are unused but
176 * have to be retained to preserve a function signature
177 * that must match that of another function.
178 * Some arguments are only used in *some* conditional compilation code paths
183 /* GCC, clang, and some ICC pretending to be GCC */
184 # define gmx_unused __attribute__ ((unused))
185 #elif (defined(__INTEL_COMPILER) || defined(__ECC)) && !defined(_MSC_VER)
187 # define gmx_unused __attribute__ ((unused))
189 /* Portland group compilers */
190 # define gmx_unused __attribute__ ((unused))
191 #elif defined _MSC_VER
193 # define gmx_unused /*@unused@*/
194 #elif defined(__xlC__)
196 # define gmx_unused __attribute__ ((unused))
202 /*! \brief Attribute to explicitly indicate that a parameter or
203 * locally scoped variable is used just in debug mode.
205 * \ingroup module_utility
208 #define gmx_used_in_debug gmx_unused
210 #define gmx_used_in_debug
213 #ifndef __has_feature
214 /** For compatibility with non-clang compilers. */
215 #define __has_feature(x) 0
219 * Macro to explicitly ignore an unused value.
221 * \ingroup module_utility
223 * \todo Deprecated - use gmx_unused
225 #define GMX_UNUSED_VALUE(value) (void)value
232 /*! \cond internal */
234 * Helper for ignoring values in macros.
236 * \ingroup module_utility
238 template <typename T>
239 static inline void ignoreValueHelper(const T &)
243 } // namespace internal
247 * Macro to explicitly ignore a return value of a call.
249 * Mainly meant for ignoring values of functions declared with
250 * `__attribute__((warn_unused_return))`. Makes it easy to find those places if
251 * they need to be fixed, and document the intent in cases where the return
252 * value really can be ignored. It also makes it easy to adapt the approach so
253 * that they don't produce warnings. A cast to void doesn't remove the warning
254 * in gcc, while adding a dummy variable can cause warnings about an unused
257 * \ingroup module_utility
259 #define GMX_IGNORE_RETURN_VALUE(call) \
260 ::gmx::internal::ignoreValueHelper(call)