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,2021, 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 any pretending to be or based on them */
108 # define gmx_unused __attribute__((unused))
109 # elif defined(__PGI)
110 /* Portland group compilers */
111 # define gmx_unused __attribute__((unused))
112 # elif defined _MSC_VER
114 # define gmx_unused /*@unused@*/
115 # elif defined(__xlC__)
117 # define gmx_unused __attribute__((unused))
123 /*! \brief Attribute to explicitly indicate that a parameter or
124 * locally scoped variable is used just in debug mode.
126 * \ingroup module_utility
129 # define gmx_used_in_debug gmx_unused
131 # define gmx_used_in_debug
134 #ifndef __has_feature
135 /** For compatibility with non-clang compilers. */
136 # define __has_feature(x) 0
140 * Macro to explicitly ignore an unused value.
142 * \ingroup module_utility
144 * \todo Deprecated - use gmx_unused
146 #define GMX_UNUSED_VALUE(value) (void)value
149 # define DO_PRAGMA(x) _Pragma(# x)
150 # define CLANG_DIAGNOSTIC_IGNORE(warning) \
151 _Pragma("clang diagnostic push") DO_PRAGMA(clang diagnostic ignored #warning)
152 # define CLANG_DIAGNOSTIC_RESET _Pragma("clang diagnostic pop")
154 //! Ignore specified clang warning until CLANG_DIAGNOSTIC_RESET
155 # define CLANG_DIAGNOSTIC_IGNORE(warning)
156 //! Reset all diagnostics to default
157 # define CLANG_DIAGNOSTIC_RESET
161 # define MSVC_DIAGNOSTIC_IGNORE(id) __pragma(warning(push)) __pragma(warning(disable : id))
162 # define MSVC_DIAGNOSTIC_RESET __pragma(warning(pop))
164 //! Ignore specified MSVC warning until MSVC_DIAGNOSTIC_RESET
165 # define MSVC_DIAGNOSTIC_IGNORE(warning)
166 //! Reset all diagnostics to default
167 # define MSVC_DIAGNOSTIC_RESET
174 /*! \cond internal */
176 * Helper for ignoring values in macros.
178 * \ingroup module_utility
181 static inline void ignoreValueHelper(const T& /*unused*/)
185 } // namespace internal
189 * Macro to explicitly ignore a return value of a call.
191 * Mainly meant for ignoring values of functions declared with
192 * `__attribute__((warn_unused_return))`. Makes it easy to find those places if
193 * they need to be fixed, and document the intent in cases where the return
194 * value really can be ignored. It also makes it easy to adapt the approach so
195 * that they don't produce warnings. A cast to void doesn't remove the warning
196 * in gcc, while adding a dummy variable can cause warnings about an unused
199 * \ingroup module_utility
201 #define GMX_IGNORE_RETURN_VALUE(call) ::gmx::internal::ignoreValueHelper(call)