Declare __STDC_*_MACROS in gmxpre.h
[alexxy/gromacs.git] / src / gromacs / utility / basedefinitions.h
index c8e65c2848da6f52584faaec4790145200ff4c97..10ed2c7f6df3d40908406808746e8abd85d84d05 100644 (file)
 
 /* Information about integer data type sizes */
 #include <limits.h>
-#define __STDC_LIMIT_MACROS
 #include <stdint.h>
 #ifndef _MSC_VER
-#define __STDC_FORMAT_MACROS
 #include <inttypes.h>
 #endif
 
@@ -159,9 +157,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
@@ -177,6 +191,9 @@ typedef uint64_t gmx_uint64_t;
 #elif (defined(__INTEL_COMPILER) || defined(__ECC)) && !defined(_MSC_VER)
 /* ICC on *nix */
 #  define gmx_unused __attribute__ ((unused))
+#elif defined(__PGI)
+/* Portland group compilers */
+#  define gmx_unused __attribute__ ((unused))
 #elif defined _MSC_VER
 /* MSVC */
 #  define gmx_unused /*@unused@*/
@@ -188,4 +205,25 @@ typedef uint64_t gmx_uint64_t;
 #endif
 #endif
 
+#ifndef __has_feature
+/** For compatibility with non-clang compilers. */
+#define __has_feature(x) 0
+#endif
+
+/*! \def gmx_noreturn
+ * \brief
+ * Indicate that a function is not expected to return.
+ *
+ */
+#ifndef gmx_noreturn
+#if defined(__GNUC__) || __has_feature(attribute_analyzer_noreturn)
+#define gmx_noreturn __attribute__((noreturn))
+#elif defined (_MSC_VER)
+#define gmx_noreturn __declspec(noreturn)
+#else
+#define gmx_noreturn
+#endif
+#endif
+
+
 #endif