# [PATCH 2/2] MSVC: VS2013 comes with inttypes.h

9 messages from 2016-03-29 to 2016-03-30. Participants: Sven Strickroth, Junio C Hamano, Sebastian Schuberth, Johannes Schindelin.
Thread: https://gitlist.dev/t/41864

## Sven Strickroth, 2016-03-29 16:27

Subject: [PATCH 2/2] MSVC: VS2013 comes with inttypes.h
Message-ID: <56FAACD4.9080504@cs-ware.de>
URL: https://gitlist.dev/e/56FAACD4.9080504%40cs-ware.de

```
Reduce the number of defines which need to be managed within vanilal git.

Signed-off-by: Sven Strickroth <sven@cs-ware.de>
---
 compat/mingw.h                  | 2 +-
 compat/vcbuild/include/unistd.h | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/compat/mingw.h b/compat/mingw.h
index 6b6d695..5d7f0dd 100644
--- a/compat/mingw.h
+++ b/compat/mingw.h
@@ -415,7 +415,7 @@ int mingw_offset_1st_component(const char *path);
 extern void build_libgit_environment(void);
 extern const char *program_data_config(void);
 #define git_program_data_config program_data_config
-#ifndef __MINGW64_VERSION_MAJOR
+#if !defined(__MINGW64_VERSION_MAJOR) || !defined(_MSC_VER) || _MSC_VER < 1800
 #define PRIuMAX "I64u"
 #define PRId64 "I64d"
 #else
diff --git a/compat/vcbuild/include/unistd.h b/compat/vcbuild/include/unistd.h
index c65c2cd..b4b7b7c 100644
--- a/compat/vcbuild/include/unistd.h
+++ b/compat/vcbuild/include/unistd.h
@@ -45,11 +45,13 @@ typedef unsigned long long uintmax_t;
 
 typedef int64_t off64_t;
 
+#if !defined(_MSC_VER) || _MSC_VER < 1800
 #define INTMAX_MIN  _I64_MIN
 #define INTMAX_MAX  _I64_MAX
 #define UINTMAX_MAX _UI64_MAX
 
 #define UINT32_MAX 0xffffffff  /* 4294967295U */
+#endif
 
 #define STDIN_FILENO  0
 #define STDOUT_FILENO 1
-- 
2.7.4.windows.1

```

## Junio C Hamano, 2016-03-29 16:47

Subject: Re: [PATCH 2/2] MSVC: VS2013 comes with inttypes.h
Message-ID: <xmqqegatz0xi.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqqegatz0xi.fsf%40gitster.mtv.corp.google.com
In-Reply-To: <56FAACD4.9080504@cs-ware.de>

```
Sven Strickroth <sven@cs-ware.de> writes:

> Reduce the number of defines which need to be managed within vanilal git.

Hmph.

>
> Signed-off-by: Sven Strickroth <sven@cs-ware.de>
> ---

I am not qualified to judge the correctness of the assertions this
change makes:

 * MSVC at or newer than version 1800 have PRIuMAX and PRId64
 * MSVC at or newer than version 1800 have {UINT,INT}MAX_{MIN,MAX}

and will wait for Windows folks to Ack.

Thanks.

>  compat/mingw.h                  | 2 +-
>  compat/vcbuild/include/unistd.h | 2 ++
>  2 files changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/compat/mingw.h b/compat/mingw.h
> index 6b6d695..5d7f0dd 100644
> --- a/compat/mingw.h
> +++ b/compat/mingw.h
> @@ -415,7 +415,7 @@ int mingw_offset_1st_component(const char *path);
>  extern void build_libgit_environment(void);
>  extern const char *program_data_config(void);
>  #define git_program_data_config program_data_config
> -#ifndef __MINGW64_VERSION_MAJOR
> +#if !defined(__MINGW64_VERSION_MAJOR) || !defined(_MSC_VER) || _MSC_VER < 1800
>  #define PRIuMAX "I64u"
>  #define PRId64 "I64d"
>  #else
> diff --git a/compat/vcbuild/include/unistd.h b/compat/vcbuild/include/unistd.h
> index c65c2cd..b4b7b7c 100644
> --- a/compat/vcbuild/include/unistd.h
> +++ b/compat/vcbuild/include/unistd.h
> @@ -45,11 +45,13 @@ typedef unsigned long long uintmax_t;
>  
>  typedef int64_t off64_t;
>  
> +#if !defined(_MSC_VER) || _MSC_VER < 1800
>  #define INTMAX_MIN  _I64_MIN
>  #define INTMAX_MAX  _I64_MAX
>  #define UINTMAX_MAX _UI64_MAX
>  
>  #define UINT32_MAX 0xffffffff  /* 4294967295U */
> +#endif
>  
>  #define STDIN_FILENO  0
>  #define STDOUT_FILENO 1

```

## Sven Strickroth, 2016-03-29 17:23

Subject: Re: [PATCH 2/2 V2] MSVC: VS2013 comes with inttypes.h
Message-ID: <56FAB9FD.7080409@cs-ware.de>
URL: https://gitlist.dev/e/56FAB9FD.7080409%40cs-ware.de
In-Reply-To: <56FAACD4.9080504@cs-ware.de>

```
Signed-off-by: Sven Strickroth <email@cs-ware.de>
---
 compat/mingw.h                  | 2 +-
 compat/vcbuild/include/unistd.h | 4 ++++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/compat/mingw.h b/compat/mingw.h
index 6b6d695..137f42e 100644
--- a/compat/mingw.h
+++ b/compat/mingw.h
@@ -415,7 +415,7 @@ int mingw_offset_1st_component(const char *path);
 extern void build_libgit_environment(void);
 extern const char *program_data_config(void);
 #define git_program_data_config program_data_config
-#ifndef __MINGW64_VERSION_MAJOR
+#if !defined(__MINGW64_VERSION_MAJOR) && (!defined(_MSC_VER) || _MSC_VER < 1800)
 #define PRIuMAX "I64u"
 #define PRId64 "I64d"
 #else
diff --git a/compat/vcbuild/include/unistd.h b/compat/vcbuild/include/unistd.h
index c65c2cd..b7cc48c 100644
--- a/compat/vcbuild/include/unistd.h
+++ b/compat/vcbuild/include/unistd.h
@@ -45,11 +45,15 @@ typedef unsigned long long uintmax_t;
 
 typedef int64_t off64_t;
 
+#if !defined(_MSC_VER) || _MSC_VER < 1800
 #define INTMAX_MIN  _I64_MIN
 #define INTMAX_MAX  _I64_MAX
 #define UINTMAX_MAX _UI64_MAX
 
 #define UINT32_MAX 0xffffffff  /* 4294967295U */
+#else
+#include<inttypes.h>
+#endif
 
 #define STDIN_FILENO  0
 #define STDOUT_FILENO 1
-- 
2.7.4.windows.1

```

## Junio C Hamano, 2016-03-29 17:35

Subject: Re: [PATCH 2/2 V2] MSVC: VS2013 comes with inttypes.h
Message-ID: <xmqq4mbpyyp3.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqq4mbpyyp3.fsf%40gitster.mtv.corp.google.com
In-Reply-To: <56FAB9FD.7080409@cs-ware.de>

```
Sven Strickroth <sven@cs-ware.de> writes:

> Signed-off-by: Sven Strickroth <email@cs-ware.de>
> ---

Ah, I didn't finish the comment I started to write here for the
first round.  My "Hmph" was meant to be followed by something like
"Compared to 1/2 which clearly described what got changed, this does
not say much to summarize what it did to help readers".

Re-reading the patch text, I tend to agree with you that the title
"comes with inttypes.h" may be sufficient for readers to reason
about the change, and it would not be necessary to explain that we
can lose fallback definitions by including it.

>  compat/mingw.h                  | 2 +-
>  compat/vcbuild/include/unistd.h | 4 ++++
>  2 files changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/compat/mingw.h b/compat/mingw.h
> index 6b6d695..137f42e 100644
> --- a/compat/mingw.h
> +++ b/compat/mingw.h
> @@ -415,7 +415,7 @@ int mingw_offset_1st_component(const char *path);
>  extern void build_libgit_environment(void);
>  extern const char *program_data_config(void);
>  #define git_program_data_config program_data_config
> -#ifndef __MINGW64_VERSION_MAJOR
> +#if !defined(__MINGW64_VERSION_MAJOR) && (!defined(_MSC_VER) || _MSC_VER < 1800)
>  #define PRIuMAX "I64u"
>  #define PRId64 "I64d"
>  #else
> diff --git a/compat/vcbuild/include/unistd.h b/compat/vcbuild/include/unistd.h
> index c65c2cd..b7cc48c 100644
> --- a/compat/vcbuild/include/unistd.h
> +++ b/compat/vcbuild/include/unistd.h
> @@ -45,11 +45,15 @@ typedef unsigned long long uintmax_t;
>  
>  typedef int64_t off64_t;
>  
> +#if !defined(_MSC_VER) || _MSC_VER < 1800
>  #define INTMAX_MIN  _I64_MIN
>  #define INTMAX_MAX  _I64_MAX
>  #define UINTMAX_MAX _UI64_MAX
>  
>  #define UINT32_MAX 0xffffffff  /* 4294967295U */
> +#else
> +#include<inttypes.h>

Somebody lost a SP here, it seems.

> +#endif
>  
>  #define STDIN_FILENO  0
>  #define STDOUT_FILENO 1

```

## Sebastian Schuberth, 2016-03-30 08:52

Subject: Re: [PATCH 2/2 V2] MSVC: VS2013 comes with inttypes.h
Message-ID: <56FB93B9.7090306@gmail.com>
URL: https://gitlist.dev/e/56FB93B9.7090306%40gmail.com
In-Reply-To: <56FAB9FD.7080409@cs-ware.de>

```
On 3/29/2016 19:23, Sven Strickroth wrote:

> --- a/compat/mingw.h
> +++ b/compat/mingw.h
> @@ -415,7 +415,7 @@ int mingw_offset_1st_component(const char *path);
>   extern void build_libgit_environment(void);
>   extern const char *program_data_config(void);
>   #define git_program_data_config program_data_config
> -#ifndef __MINGW64_VERSION_MAJOR
> +#if !defined(__MINGW64_VERSION_MAJOR) && (!defined(_MSC_VER) || _MSC_VER < 1800)
>   #define PRIuMAX "I64u"
>   #define PRId64 "I64d"
>   #else

ACK for this part. For reference see [1].

> diff --git a/compat/vcbuild/include/unistd.h b/compat/vcbuild/include/unistd.h
> index c65c2cd..b7cc48c 100644
> --- a/compat/vcbuild/include/unistd.h
> +++ b/compat/vcbuild/include/unistd.h
> @@ -45,11 +45,15 @@ typedef unsigned long long uintmax_t;
>   
>   typedef int64_t off64_t;
>   
> +#if !defined(_MSC_VER) || _MSC_VER < 1800
>   #define INTMAX_MIN  _I64_MIN
>   #define INTMAX_MAX  _I64_MAX
>   #define UINTMAX_MAX _UI64_MAX
>   
>   #define UINT32_MAX 0xffffffff  /* 4294967295U */
> +#else
> +#include<inttypes.h>
> +#endif

If we would do "#include <stdint.h>" here instead, we could lower the _MSC_VER requirement to at least 1700. According to the comment at [2] we could lower it even to 1600.

Also the original code is missing a single space after "#include".

[1] https://blogs.msdn.microsoft.com/vcblog/2013/07/19/c99-library-support-in-visual-studio-2013/
[2] https://stackoverflow.com/questions/126279/c99-stdint-h-header-and-ms-visual-studio#comment4620359_126279

Regards,
Sebastian

```

## Sven Strickroth, 2016-03-30 11:37

Subject: Re: [PATCH 2/2 V3] MSVC: Use shipped headers instead of fallback definitions
Message-ID: <56FBBA80.8090908@cs-ware.de>
URL: https://gitlist.dev/e/56FBBA80.8090908%40cs-ware.de
In-Reply-To: <56FB93B9.7090306@gmail.com>

```
VS2010 comes with stdint.h [1]
VS2013 comes with inttypes.h [2]

[1] https://stackoverflow.com/a/2628014/3906760
[2] https://blogs.msdn.microsoft.com/vcblog/2013/07/19/c99-library-support-in-visual-studio-2013/

Signed-off-by: Sven Strickroth <sven@cs-ware.de>
---
 compat/mingw.h                  | 2 +-
 compat/vcbuild/include/unistd.h | 4 ++++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/compat/mingw.h b/compat/mingw.h
index 6b6d695..137f42e 100644
--- a/compat/mingw.h
+++ b/compat/mingw.h
@@ -415,7 +415,7 @@ int mingw_offset_1st_component(const char *path);
 extern void build_libgit_environment(void);
 extern const char *program_data_config(void);
 #define git_program_data_config program_data_config
-#ifndef __MINGW64_VERSION_MAJOR
+#if !defined(__MINGW64_VERSION_MAJOR) && (!defined(_MSC_VER) || _MSC_VER < 1800)
 #define PRIuMAX "I64u"
 #define PRId64 "I64d"
 #else
diff --git a/compat/vcbuild/include/unistd.h b/compat/vcbuild/include/unistd.h
index c65c2cd..b7cc48c 100644
--- a/compat/vcbuild/include/unistd.h
+++ b/compat/vcbuild/include/unistd.h
@@ -45,11 +45,15 @@ typedef unsigned long long uintmax_t;
 
 typedef int64_t off64_t;
 
+#if !defined(_MSC_VER) || _MSC_VER < 1600
 #define INTMAX_MIN  _I64_MIN
 #define INTMAX_MAX  _I64_MAX
 #define UINTMAX_MAX _UI64_MAX
 
 #define UINT32_MAX 0xffffffff  /* 4294967295U */
+#else
+#include <stdint.h>
+#endif
 
 #define STDIN_FILENO  0
 #define STDOUT_FILENO 1
-- 
2.7.4.windows.1

```

## Sebastian Schuberth, 2016-03-30 11:40

Subject: Re: [PATCH 2/2 V3] MSVC: Use shipped headers instead of fallback definitions
Message-ID: <56FBBB3B.8000004@gmail.com>
URL: https://gitlist.dev/e/56FBBB3B.8000004%40gmail.com
In-Reply-To: <56FBBA80.8090908@cs-ware.de>

```
On 3/30/2016 13:37, Sven Strickroth wrote:

> VS2010 comes with stdint.h [1]
> VS2013 comes with inttypes.h [2]
>
> [1] https://stackoverflow.com/a/2628014/3906760
> [2] https://blogs.msdn.microsoft.com/vcblog/2013/07/19/c99-library-support-in-visual-studio-2013/
>
> Signed-off-by: Sven Strickroth <sven@cs-ware.de>

ACK.

Regards,
Sebastian

```

## Johannes Schindelin, 2016-03-30 11:42

Subject: Re: [PATCH 2/2 V3] MSVC: Use shipped headers instead of fallback definitions
Message-ID: <alpine.DEB.2.20.1603301341120.4690@virtualbox>
URL: https://gitlist.dev/e/alpine.DEB.2.20.1603301341120.4690%40virtualbox
In-Reply-To: <56FBBA80.8090908@cs-ware.de>

```
Hi Sven,

On Wed, 30 Mar 2016, Sven Strickroth wrote:

> VS2010 comes with stdint.h [1]
> VS2013 comes with inttypes.h [2]
> 
> [1] https://stackoverflow.com/a/2628014/3906760
> [2] https://blogs.msdn.microsoft.com/vcblog/2013/07/19/c99-library-support-in-visual-studio-2013/
> 
> Signed-off-by: Sven Strickroth <sven@cs-ware.de>

Much, much, much better commit message (even if there is still room for
a more pleasant read).

ACK
Dscho

```

## Junio C Hamano, 2016-03-30 18:19

Subject: Re: [PATCH 2/2 V3] MSVC: Use shipped headers instead of fallback definitions
Message-ID: <xmqqbn5vu8ve.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqqbn5vu8ve.fsf%40gitster.mtv.corp.google.com
In-Reply-To: <56FBBA80.8090908@cs-ware.de>

```
Sven Strickroth <sven@cs-ware.de> writes:

> diff --git a/compat/mingw.h b/compat/mingw.h
> index 6b6d695..137f42e 100644
> --- a/compat/mingw.h
> +++ b/compat/mingw.h
> @@ -415,7 +415,7 @@ int mingw_offset_1st_component(const char *path);
>  extern void build_libgit_environment(void);
>  extern const char *program_data_config(void);
>  #define git_program_data_config program_data_config
> -#ifndef __MINGW64_VERSION_MAJOR
> +#if !defined(__MINGW64_VERSION_MAJOR) && (!defined(_MSC_VER) || _MSC_VER < 1800)
>  #define PRIuMAX "I64u"
>  #define PRId64 "I64d"
>  #else

I'll wiggle this in, but you seem to be building on top of some
unrelated work (please avoid sending such a patch in the future).

Thanks, all of you.

-- >8 --
From: Sven Strickroth <sven@cs-ware.de>
Date: Wed, 30 Mar 2016 13:37:36 +0200
Subject: [PATCH] MSVC: use shipped headers instead of fallback definitions

VS2010 comes with stdint.h [1]
VS2013 comes with inttypes.h [2]

[1] https://stackoverflow.com/a/2628014/3906760
[2] https://blogs.msdn.microsoft.com/vcblog/2013/07/19/c99-library-support-in-visual-studio-2013/

Signed-off-by: Sven Strickroth <sven@cs-ware.de>
Acked-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Acked-by: Sebastian Schuberth <sschuberth@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 compat/mingw.h                  | 2 +-
 compat/vcbuild/include/unistd.h | 4 ++++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/compat/mingw.h b/compat/mingw.h
index c008694..1de70ff 100644
--- a/compat/mingw.h
+++ b/compat/mingw.h
@@ -406,7 +406,7 @@ static inline void convert_slashes(char *path)
 int mingw_offset_1st_component(const char *path);
 #define offset_1st_component mingw_offset_1st_component
 #define PATH_SEP ';'
-#ifndef __MINGW64_VERSION_MAJOR
+#if !defined(__MINGW64_VERSION_MAJOR) && (!defined(_MSC_VER) || _MSC_VER < 1800)
 #define PRIuMAX "I64u"
 #define PRId64 "I64d"
 #else
diff --git a/compat/vcbuild/include/unistd.h b/compat/vcbuild/include/unistd.h
index c65c2cd..3a959d1 100644
--- a/compat/vcbuild/include/unistd.h
+++ b/compat/vcbuild/include/unistd.h
@@ -45,11 +45,15 @@ typedef unsigned long long uintmax_t;
 
 typedef int64_t off64_t;
 
+#if !defined(_MSC_VER) || _MSC_VER < 1600
 #define INTMAX_MIN  _I64_MIN
 #define INTMAX_MAX  _I64_MAX
 #define UINTMAX_MAX _UI64_MAX
 
 #define UINT32_MAX 0xffffffff  /* 4294967295U */
+#else
+#include <stdint.h>
+#endif
 
 #define STDIN_FILENO  0
 #define STDOUT_FILENO 1
-- 
2.8.0-215-gd29a7d9

```
