Make vec.h const-correct with both C and C++
[alexxy/gromacs.git] / src / gromacs / utility / basedefinitions.h
index c8e65c2848da6f52584faaec4790145200ff4c97..18a898cce5f6e919bd5e33c5f47437806db30038 100644 (file)
@@ -159,9 +159,25 @@ typedef uint64_t gmx_uint64_t;
  */
 #define gmx_restrict __restrict
 
+/*! \def gmx_cxx_const
+ * \brief
+ * Keyword to work around C/C++ differences in possible const keyword usage.
+ *
+ * Some functions that do not modify their input parameters cannot declare
+ * those parameters as `const` and compile warning/error-free on both C and C++
+ * compilers because of differences in `const` semantics.  This macro can be
+ * used in cases where C++ allows `const`, but C does not like it, to make the
+ * same declaration work for both.
+ */
+#ifdef __cplusplus
+#define gmx_cxx_const const
+#else
+#define gmx_cxx_const
+#endif
+
 /*! \def gmx_unused
  * \brief
- * Attribute to suppres compiler warnings about unused function parameters.
+ * Attribute to suppress compiler warnings about unused function parameters.
  *
  * This attribute suppresses compiler warnings about unused function arguments
  * by marking them as possibly unused.  Some arguments are unused but