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
49 #if defined __cplusplus
57 typedef bool gmx_bool;
60 /** False value for ::gmx_bool. */
64 /** True value for ::gmx_bool. */
67 /** Number of gmx_bool values. */
70 #if defined __cplusplus
73 /*! \brief Integer type for indexing into arrays or vectors
77 using index = std::ptrdiff_t;
81 /* ICC, GCC, MSVC, Pathscale, PGI, XLC support __restrict.
82 * Any other compiler can be added here. */
84 * Keyword to use in instead of C99 `restrict`.
86 * We cannot use `restrict` because it is only in C99, but not in C++.
87 * This macro should instead be used to allow easily supporting different
90 #define gmx_restrict __restrict
92 /*! \def GMX_CXX11_COMPILATION
94 * Defined to 1 when compiling as C++11.
96 * While \Gromacs only supports C++11 compilation, there are some parts of the
97 * code that are compiled with other tools than the actual C++ compiler, and
98 * these may not support C++11. Most notable such case is all of CUDA code
99 * (with CUDA versions older than 6.5), but other types of kernels might also
100 * have similar limitations in the future.
102 * The define is intended for conditional compilation in low-level headers that
103 * need to support inclusion from such non-C++11 files, but get significant
104 * benefit (e.g., for correctness checking or more convenient use) from C++11.
105 * It should only be used for features that do not influence the ABI of the
106 * header; e.g., static_asserts or additional helper methods.
108 #if defined __cplusplus && __cplusplus >= 201103L
109 # define GMX_CXX11_COMPILATION 1
111 # define GMX_CXX11_COMPILATION 0
116 * Attribute to suppress compiler warnings about unused function parameters.
118 * This attribute suppresses compiler warnings about unused function arguments
119 * by marking them as possibly unused. Some arguments are unused but
120 * have to be retained to preserve a function signature
121 * that must match that of another function.
122 * Some arguments are only used in *some* conditional compilation code paths
127 /* GCC, clang, and some ICC pretending to be GCC */
128 # define gmx_unused __attribute__ ((unused))
129 #elif (defined(__INTEL_COMPILER) || defined(__ECC)) && !defined(_MSC_VER)
131 # define gmx_unused __attribute__ ((unused))
133 /* Portland group compilers */
134 # define gmx_unused __attribute__ ((unused))
135 #elif defined _MSC_VER
137 # define gmx_unused /*@unused@*/
138 #elif defined(__xlC__)
140 # define gmx_unused __attribute__ ((unused))
146 /*! \brief Attribute to explicitly indicate that a parameter or
147 * locally scoped variable is used just in debug mode.
149 * \ingroup module_utility
152 #define gmx_used_in_debug gmx_unused
154 #define gmx_used_in_debug
157 #ifndef __has_feature
158 /** For compatibility with non-clang compilers. */
159 #define __has_feature(x) 0
163 * Macro to explicitly ignore an unused value.
165 * \ingroup module_utility
167 * \todo Deprecated - use gmx_unused
169 #define GMX_UNUSED_VALUE(value) (void)value
176 /*! \cond internal */
178 * Helper for ignoring values in macros.
180 * \ingroup module_utility
182 template <typename T>
183 static inline void ignoreValueHelper(const T &)
187 } // namespace internal
191 * Macro to explicitly ignore a return value of a call.
193 * Mainly meant for ignoring values of functions declared with
194 * `__attribute__((warn_unused_return))`. Makes it easy to find those places if
195 * they need to be fixed, and document the intent in cases where the return
196 * value really can be ignored. It also makes it easy to adapt the approach so
197 * that they don't produce warnings. A cast to void doesn't remove the warning
198 * in gcc, while adding a dummy variable can cause warnings about an unused
201 * \ingroup module_utility
203 #define GMX_IGNORE_RETURN_VALUE(call) \
204 ::gmx::internal::ignoreValueHelper(call)