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 by the GROMACS development team.
7 * Copyright (c) 2018,2019,2020, by the GROMACS development team, led by
8 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
9 * and including many others, as listed in the AUTHORS file in the
10 * top-level source directory and at http://www.gromacs.org.
12 * GROMACS is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public License
14 * as published by the Free Software Foundation; either version 2.1
15 * of the License, or (at your option) any later version.
17 * GROMACS is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with GROMACS; if not, see
24 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
25 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 * If you want to redistribute modifications to GROMACS, please
28 * consider that scientific software is very special. Version
29 * control is crucial - bugs must be traceable. We will be happy to
30 * consider code for inclusion in the official distribution, but
31 * derived work must not be called official GROMACS. Details are found
32 * in the README & COPYING files - if they are missing, get the
33 * official version at http://www.gromacs.org.
35 * To help us fund GROMACS development, we humbly ask that you cite
36 * the research papers on the package. Check out http://www.gromacs.org.
40 * Basic types and macros used throughout \Gromacs.
43 * \ingroup module_utility
45 #ifndef GMX_UTILITY_BASEDEFINITIONS_H
46 #define GMX_UTILITY_BASEDEFINITIONS_H
54 typedef bool gmx_bool;
57 /** False value for ::gmx_bool. */
61 /** True value for ::gmx_bool. */
64 /** Number of gmx_bool values. */
69 /*! \brief Integer type for indexing into arrays or vectors
73 using index = std::ptrdiff_t;
75 //! Return signed size of container
77 index ssize(const T& t)
83 /* ICC, GCC, MSVC, Pathscale, PGI, XLC support __restrict.
84 * Any other compiler can be added here. */
86 * Keyword to use in instead of C99 `restrict`.
88 * We cannot use `restrict` because it is only in C99, but not in C++.
89 * This macro should instead be used to allow easily supporting different
92 #define gmx_restrict __restrict
96 * Attribute to suppress compiler warnings about unused function parameters.
98 * This attribute suppresses compiler warnings about unused function arguments
99 * by marking them as possibly unused. Some arguments are unused but
100 * have to be retained to preserve a function signature
101 * that must match that of another function.
102 * Some arguments are only used in *some* conditional compilation code paths
107 /* GCC, clang, and some ICC pretending to be GCC */
108 # define gmx_unused __attribute__((unused))
109 # elif (defined(__INTEL_COMPILER) || defined(__ECC)) && !defined(_MSC_VER)
111 # define gmx_unused __attribute__((unused))
112 # elif defined(__PGI)
113 /* Portland group compilers */
114 # define gmx_unused __attribute__((unused))
115 # elif defined _MSC_VER
117 # define gmx_unused /*@unused@*/
118 # elif defined(__xlC__)
120 # define gmx_unused __attribute__((unused))
126 /*! \brief Attribute to explicitly indicate that a parameter or
127 * locally scoped variable is used just in debug mode.
129 * \ingroup module_utility
132 # define gmx_used_in_debug gmx_unused
134 # define gmx_used_in_debug
137 #ifndef __has_feature
138 /** For compatibility with non-clang compilers. */
139 # define __has_feature(x) 0
143 * Macro to explicitly ignore an unused value.
145 * \ingroup module_utility
147 * \todo Deprecated - use gmx_unused
149 #define GMX_UNUSED_VALUE(value) (void)value
152 # define DO_PRAGMA(x) _Pragma(# x)
153 # define CLANG_DIAGNOSTIC_IGNORE(warning) \
154 _Pragma("clang diagnostic push") DO_PRAGMA(clang diagnostic ignored #warning)
155 # define CLANG_DIAGNOSTIC_RESET _Pragma("clang diagnostic pop")
157 //! Ignore specified clang warning until CLANG_DIAGNOSTIC_RESET
158 # define CLANG_DIAGNOSTIC_IGNORE(warning)
159 //! Reset all diagnostics to default
160 # define CLANG_DIAGNOSTIC_RESET
164 # define MSVC_DIAGNOSTIC_IGNORE(id) __pragma(warning(push)) __pragma(warning(disable : id))
165 # define MSVC_DIAGNOSTIC_RESET __pragma(warning(pop))
167 //! Ignore specified MSVC warning until MSVC_DIAGNOSTIC_RESET
168 # define MSVC_DIAGNOSTIC_IGNORE(warning)
169 //! Reset all diagnostics to default
170 # define MSVC_DIAGNOSTIC_RESET
177 /*! \cond internal */
179 * Helper for ignoring values in macros.
181 * \ingroup module_utility
184 static inline void ignoreValueHelper(const T& /*unused*/)
188 } // namespace internal
192 * Macro to explicitly ignore a return value of a call.
194 * Mainly meant for ignoring values of functions declared with
195 * `__attribute__((warn_unused_return))`. Makes it easy to find those places if
196 * they need to be fixed, and document the intent in cases where the return
197 * value really can be ignored. It also makes it easy to adapt the approach so
198 * that they don't produce warnings. A cast to void doesn't remove the warning
199 * in gcc, while adding a dummy variable can cause warnings about an unused
202 * \ingroup module_utility
204 #define GMX_IGNORE_RETURN_VALUE(call) ::gmx::internal::ignoreValueHelper(call)