Nek5000 / gslib

sparse communication library
Other
26 stars 26 forks source link

Using limits.sh to discover uint, ulong, llong limits #21

Closed RonRahaman closed 6 years ago

RonRahaman commented 6 years ago

This PR uses the POSIX-standard limits.h header to discover the limits for several variable types in a compliant fashion.

There are several places where gslib needs to discover the maximum value of an unsigned type. Currently, it does so via a narrowing type conversion. For example:

uint limit = -(uint)1

However, these limits are already provided by macros in limits.h. This can avoid possible pitfalls from a narrowing conversion. A more compliant version (implemented in this PR) looks like:

#include <limits.h>
uint limit = UINT_MAX

There was also one place in types.h where LLONG_MIN and LLONG_MAX were set, if long long is requested by the user. Now, these limits are also taken from limits.h