Shifting toward C99
Motivating reasons
- Third party components are shifting to C99.
- hwloc
- hwloc is required in MPICH and it requires C99.
- ucx
- ucx is optional in MPICH and it requires C99.
- ofi.
- ofi is optional in MPICH and it requires C99.
- ch4
- CH4 device requires either ucx or ofi.
- C99 requirement simplifies portability burden.
- <stdbool.h>, <stdint.h>, <complex.h>
- restrict pointers and inline functions
- C99 allows better code readability
- declaring variables close to its context
- defining loop variables within the loop syntax
- variable length array
- compound literals
Potential impact
The main concern of shifting to C99 is that certain platforms with absent or less-complete C99 compiler support will not be able to build MPICH.
Reference compiler quirks page for the status of compiler support.
MPICH specific C99 features
Even as we shifting to C99 requirement, we are not opening the flood gate to allow all C99 features into the codebase. The full support of C99 features may put unnecessary restrictions on compilers. By limiting allowed C99 features, we intend to support as many compilers as we can. In addition, even when certain feature may not be supported by a particular compiler, the limited feature allowance may still provide feasible path for back porting.
The standardized data type support -- stdbool.h, stdint.h, complex.h -- are in.
Mixing variable declarations and code are case dependent. In general, we prefers to have variables all declared at the top of scope. However, for temporary variables that are only meaningful over partial code scope, we would like to have them defined where they are being used.
We generally prefer loop variables defined in the for-loop
line, as they will have no context outside the loop. However, this syntax is a lagging point in Microsoft C compiler (double check).
We still prefer C block comments. C++ style inline comments do not bring more readability other than save on typing.