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,2019,2020, 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
53 typedef bool gmx_bool;
56 /** False value for ::gmx_bool. */
60 /** True value for ::gmx_bool. */
63 /** Number of gmx_bool values. */
68 /*! \brief Integer type for indexing into arrays or vectors
72 using index = std::ptrdiff_t;
74 //! Return signed size of container
76 index ssize(const T& t)
82 /* ICC, GCC, MSVC, Pathscale, PGI, XLC support __restrict.
83 * Any other compiler can be added here. */
85 * Keyword to use in instead of C99 `restrict`.
87 * We cannot use `restrict` because it is only in C99, but not in C++.
88 * This macro should instead be used to allow easily supporting different
91 #define gmx_restrict __restrict
95 * Attribute to suppress compiler warnings about unused function parameters.
97 * This attribute suppresses compiler warnings about unused function arguments
98 * by marking them as possibly unused. Some arguments are unused but
99 * have to be retained to preserve a function signature
100 * that must match that of another function.
101 * Some arguments are only used in *some* conditional compilation code paths
106 /* GCC, clang, and some ICC pretending to be GCC */
107 # define gmx_unused __attribute__((unused))
108 # elif (defined(__INTEL_COMPILER) || defined(__ECC)) && !defined(_MSC_VER)
110 # define gmx_unused __attribute__((unused))
111 # elif defined(__PGI)
112 /* Portland group compilers */
113 # define gmx_unused __attribute__((unused))
114 # elif defined _MSC_VER
116 # define gmx_unused /*@unused@*/
117 # elif defined(__xlC__)
119 # define gmx_unused __attribute__((unused))
125 /*! \brief Attribute to explicitly indicate that a parameter or
126 * locally scoped variable is used just in debug mode.
128 * \ingroup module_utility
131 # define gmx_used_in_debug gmx_unused
133 # define gmx_used_in_debug
136 #ifndef __has_feature
137 /** For compatibility with non-clang compilers. */
138 # define __has_feature(x) 0
142 * Macro to explicitly ignore an unused value.
144 * \ingroup module_utility
146 * \todo Deprecated - use gmx_unused
148 #define GMX_UNUSED_VALUE(value) (void)value
151 # define DO_PRAGMA(x) _Pragma(# x)
152 # define CLANG_DIAGNOSTIC_IGNORE(warning) \
153 _Pragma("clang diagnostic push") DO_PRAGMA(clang diagnostic ignored #warning)
154 # define CLANG_DIAGNOSTIC_RESET _Pragma("clang diagnostic pop")
156 //! Ignore specified clang warning until CLANG_DIAGNOSTIC_RESET
157 # define CLANG_DIAGNOSTIC_IGNORE(warning)
158 //! Reset all diagnostics to default
159 # define CLANG_DIAGNOSTIC_RESET
163 # define MSVC_DIAGNOSTIC_IGNORE(id) __pragma(warning(push)) __pragma(warning(disable : id))
164 # define MSVC_DIAGNOSTIC_RESET __pragma(warning(pop))
166 //! Ignore specified MSVC warning until MSVC_DIAGNOSTIC_RESET
167 # define MSVC_DIAGNOSTIC_IGNORE(warning)
168 //! Reset all diagnostics to default
169 # define MSVC_DIAGNOSTIC_RESET
176 /*! \cond internal */
178 * Helper for ignoring values in macros.
180 * \ingroup module_utility
183 static inline void ignoreValueHelper(const T& /*unused*/)
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) ::gmx::internal::ignoreValueHelper(call)