From 22fcfd13dde2ce31faf8b38b4de078756aa2e124 Mon Sep 17 00:00:00 2001 From: Teemu Murtola Date: Fri, 12 Sep 2014 21:56:32 +0300 Subject: [PATCH] Declare __STDC_*_MACROS in gmxpre.h These free up code that needs, e.g., GMX_INT64_MAX from hard-to-satisfy constraints on the include order. More details in the comments in gmxpre.h. Also clarify our requirements for C99 support in the install guide. Change-Id: I371c3a79244340764b320ae36183dd8926fe0f94 --- docs/install-guide/install-guide.md | 3 +++ src/gmxpre.h | 14 ++++++++++++++ src/gromacs/utility/basedefinitions.h | 2 -- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/docs/install-guide/install-guide.md b/docs/install-guide/install-guide.md index 3ce470db15..095db26641 100644 --- a/docs/install-guide/install-guide.md +++ b/docs/install-guide/install-guide.md @@ -75,6 +75,9 @@ architectures including x86, AMD64/x86-64, PPC, ARM v7 and SPARC VIII. Technically, GROMACS can be compiled on any platform with an ANSI C99 and C++98 compiler, and their respective standard C/C++ libraries. +We use only a few C99 features, but note that the C++ compiler also needs to +support these C99 features (notably, int64_t and related things), which are not +part of the C++98 standard. Getting good performance on an OS and architecture requires choosing a good compiler. In practice, many compilers struggle to do a good job optimizing the GROMACS architecture-optimized SIMD kernels. diff --git a/src/gmxpre.h b/src/gmxpre.h index 3ae077ecb3..0573e37a11 100644 --- a/src/gmxpre.h +++ b/src/gmxpre.h @@ -71,6 +71,20 @@ #define _GNU_SOURCE 1 #endif +/* Some C++(?) compilers require these to be defined to get the integer limits + * and format specifier macros from stdint.h and inttypes.h, respectively. + * The macros are in C99 and C++11, but not in C++98... + * As with _GNU_SOURCE, these need to be defined before these headers get first + * included. Unlike _GNU_SOURCE, these headers are included indirectly in most + * header and source files (even though the macros are not used that often), so + * there is no easy alternative to defining them here, either. + * If someone happens to use such a compiler to compile against the installed + * Gromacs headers, they need for now take care to define the macros themselves + * (as there is no way Gromacs can do that consistently). + */ +#define __STDC_LIMIT_MACROS +#define __STDC_FORMAT_MACROS + #ifdef GMX_FAHCORE #define FULLINDIRECT 1 #define USE_FAH_XDR 1 diff --git a/src/gromacs/utility/basedefinitions.h b/src/gromacs/utility/basedefinitions.h index 4c554c5f83..10ed2c7f6d 100644 --- a/src/gromacs/utility/basedefinitions.h +++ b/src/gromacs/utility/basedefinitions.h @@ -46,10 +46,8 @@ /* Information about integer data type sizes */ #include -#define __STDC_LIMIT_MACROS #include #ifndef _MSC_VER -#define __STDC_FORMAT_MACROS #include #endif -- 2.22.0