diff mbox series

[5/7] Define LLONG_MAX/MIN etc if not already defined.

Message ID 20200518100356.29292-5-dtucker@dtucker.net (mailing list archive)
State New, archived
Headers show
Series [1/7] Redirect grep's stderr top null too. | expand

Commit Message

Darren Tucker May 18, 2020, 10:03 a.m. UTC
Signed-off-by: Darren Tucker <dtucker@dtucker.net>
---
 git-compat-util.h | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

Comments

Andreas Schwab May 18, 2020, 10:24 a.m. UTC | #1
On Mai 18 2020, Darren Tucker wrote:

> diff --git a/git-compat-util.h b/git-compat-util.h
> index 8ba576e81e..aa221eba1b 100644
> --- a/git-compat-util.h
> +++ b/git-compat-util.h
> @@ -127,6 +127,22 @@
>  /* Approximation of the length of the decimal representation of this type. */
>  #define decimal_length(x)	((int)(sizeof(x) * 2.56 + 0.5) + 1)
>  
> +#ifndef SIZE_MAX
> +#define SIZE_MAX ((size_t)maximum_signed_value_of_type(size_t))

size_t is an unsigned type.

> +#endif
> +
> +#ifndef LLONG_MIN
> +#define LLONG_MIN ((long long)minimum_signed_value_of_type(long long))
> +#endif
> +
> +#ifndef LLONG_MAX
> +#define LLONG_MAX ((long long)maximum_signed_value_of_type(long long))
> +#endif
> +
> +#ifndef ULLONG_MAX
> +#define ULLONG_MAX ((unsigned long long)maximum_unsigned_value_of_type(unsigned long long))
> +#endif

These definitions won't work in the preprocessor.  The are no current
uses of these macros in preprocessor directives, but that needs to be
kept in mind.

Andreas.
Darren Tucker May 18, 2020, 2:41 p.m. UTC | #2
On Mon, 18 May 2020 at 20:24, Andreas Schwab <schwab@linux-m68k.org> wrote:
> On Mai 18 2020, Darren Tucker wrote:
[...]
> > +#define SIZE_MAX ((size_t)maximum_signed_value_of_type(size_t))
>
> size_t is an unsigned type.

indeed; missed that in my cut and pasting.

[...]
> These definitions won't work in the preprocessor.  The are no current
> uses of these macros in preprocessor directives, but that needs to be
> kept in mind.

I originally had these defined to LONG_LONG_MAX and ULONG_LONG_MAX
which it (HP-UX 11.11) has.  It's also got SSIZE_MAX but not SIZE_MAX,
so I originally had

#if !defined(SIZE_MAX) && defined(SSIZE_MAX) && (SSIZE_MAX == LONG_MAX)
# define SIZE_MAX ULONG_MAX
#endif

which would work in macros, but I changed it at the last minute to use
those other macros since it seemed more likely to work on any other
systems that had this problem.
diff mbox series

Patch

diff --git a/git-compat-util.h b/git-compat-util.h
index 8ba576e81e..aa221eba1b 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -127,6 +127,22 @@ 
 /* Approximation of the length of the decimal representation of this type. */
 #define decimal_length(x)	((int)(sizeof(x) * 2.56 + 0.5) + 1)
 
+#ifndef SIZE_MAX
+#define SIZE_MAX ((size_t)maximum_signed_value_of_type(size_t))
+#endif
+
+#ifndef LLONG_MIN
+#define LLONG_MIN ((long long)minimum_signed_value_of_type(long long))
+#endif
+
+#ifndef LLONG_MAX
+#define LLONG_MAX ((long long)maximum_signed_value_of_type(long long))
+#endif
+
+#ifndef ULLONG_MAX
+#define ULLONG_MAX ((unsigned long long)maximum_unsigned_value_of_type(unsigned long long))
+#endif
+
 #if defined(__sun__)
  /*
   * On Solaris, when _XOPEN_EXTENDED is set, its header file