# Printing a uint64_t portably in Git?

5 messages from 2020-02-06 to 2020-02-06. Participants: Han-Wen Nienhuys, Martin Ågren, Junio C Hamano.
Thread: https://gitlist.dev/t/52754

## Han-Wen Nienhuys, 2020-02-06 17:52

Subject: Printing a uint64_t portably in Git?
Message-ID: <CAFQ2z_Pac6yb9Vi782VMtPkssNmdc08WntS7xRt8KCFfM6KVsw@mail.gmail.com>
URL: https://gitlist.dev/e/CAFQ2z_Pac6yb9Vi782VMtPkssNmdc08WntS7xRt8KCFfM6KVsw%40mail.gmail.com

```
Hi,

The reftable patch is starting to shape up, but I still see failures on OSX,

See https://dev.azure.com/gitgitgadget/git/_build/results?buildId=29465&view=logs&j=cfa20e98-6997-523c-4233-f0a7302c929f&t=3de1ae02-4adb-5138-54da-65cec5dd3141&l=518

What is the right incantation to do printf of a uint64_t on OSX ?

Apparently PRIuMAX is to be used for "uintmax_t", and not for "long
long unsigned int".

-- 
Han-Wen Nienhuys - Google Munich
I work 80%. Don't expect answers from me on Fridays.
--

Google Germany GmbH, Erika-Mann-Strasse 33, 80636 Munich

Registergericht und -nummer: Hamburg, HRB 86891

Sitz der Gesellschaft: Hamburg

Geschäftsführer: Paul Manicle, Halimah DeLaine Prado

```

## Martin Ågren, 2020-02-06 18:00

Subject: Re: Printing a uint64_t portably in Git?
Message-ID: <CAN0heSqoU1NxOtwaE_ZBBzghLXAeC4CxVh1x8R-efOVtbHdA5g@mail.gmail.com>
URL: https://gitlist.dev/e/CAN0heSqoU1NxOtwaE_ZBBzghLXAeC4CxVh1x8R-efOVtbHdA5g%40mail.gmail.com
In-Reply-To: <CAFQ2z_Pac6yb9Vi782VMtPkssNmdc08WntS7xRt8KCFfM6KVsw@mail.gmail.com>

```
On Thu, 6 Feb 2020 at 18:54, Han-Wen Nienhuys <hanwen@google.com> wrote:
> What is the right incantation to do printf of a uint64_t on OSX ?
>
> Apparently PRIuMAX is to be used for "uintmax_t", and not for "long
> long unsigned int".

You could cast it? Grepping around, that seems to be how PRIuMAX is
used:

  printf("%"PRIuMAX"\n", (uintmax_t)var);

Martin

```

## Han-Wen Nienhuys, 2020-02-06 19:15

Subject: Re: Printing a uint64_t portably in Git?
Message-ID: <CAFQ2z_Mez4khfvXx6R2K9JPagmoQWD-ZnT7rFiAW9Avjt=4PpQ@mail.gmail.com>
URL: https://gitlist.dev/e/CAFQ2z_Mez4khfvXx6R2K9JPagmoQWD-ZnT7rFiAW9Avjt%3D4PpQ%40mail.gmail.com
In-Reply-To: <CAN0heSqoU1NxOtwaE_ZBBzghLXAeC4CxVh1x8R-efOVtbHdA5g@mail.gmail.com>

```
On Thu, Feb 6, 2020 at 7:00 PM Martin Ågren <martin.agren@gmail.com> wrote:
>
> On Thu, 6 Feb 2020 at 18:54, Han-Wen Nienhuys <hanwen@google.com> wrote:
> > What is the right incantation to do printf of a uint64_t on OSX ?
> >
> > Apparently PRIuMAX is to be used for "uintmax_t", and not for "long
> > long unsigned int".
>
> You could cast it? Grepping around, that seems to be how PRIuMAX is
> used:
>
>   printf("%"PRIuMAX"\n", (uintmax_t)var);

Looks like the inttypes.h standard has the defines that I want.

-- 
Han-Wen Nienhuys - Google Munich
I work 80%. Don't expect answers from me on Fridays.
--

Google Germany GmbH, Erika-Mann-Strasse 33, 80636 Munich

Registergericht und -nummer: Hamburg, HRB 86891

Sitz der Gesellschaft: Hamburg

Geschäftsführer: Paul Manicle, Halimah DeLaine Prado

```

## Martin Ågren, 2020-02-06 19:52

Subject: Re: Printing a uint64_t portably in Git?
Message-ID: <CAN0heSrOvAdXs-8n0Cz4NMHqoxYfpStUOZcPRT1iQnA3R1srbQ@mail.gmail.com>
URL: https://gitlist.dev/e/CAN0heSrOvAdXs-8n0Cz4NMHqoxYfpStUOZcPRT1iQnA3R1srbQ%40mail.gmail.com
In-Reply-To: <CAFQ2z_Mez4khfvXx6R2K9JPagmoQWD-ZnT7rFiAW9Avjt=4PpQ@mail.gmail.com>

```
On Thu, 6 Feb 2020 at 20:15, Han-Wen Nienhuys <hanwen@google.com> wrote:
>
> On Thu, Feb 6, 2020 at 7:00 PM Martin Ågren <martin.agren@gmail.com> wrote:
> >
> > On Thu, 6 Feb 2020 at 18:54, Han-Wen Nienhuys <hanwen@google.com> wrote:
> > > What is the right incantation to do printf of a uint64_t on OSX ?
> > >
> > > Apparently PRIuMAX is to be used for "uintmax_t", and not for "long
> > > long unsigned int".
> >
> > You could cast it? Grepping around, that seems to be how PRIuMAX is
> > used:
> >
> >   printf("%"PRIuMAX"\n", (uintmax_t)var);
>
> Looks like the inttypes.h standard has the defines that I want.

Oh, cool. We handle PRIuMAX and PRId64 in compat/mingw.h, but other than
that, it seems we rely on these being available. There's some discussion
in ebc3278665 ("git-compat-util.h: drop the `PRIuMAX` and other fallback
definitions", 2019-11-24).

Martin

```

## Junio C Hamano, 2020-02-06 21:11

Subject: Re: Printing a uint64_t portably in Git?
Message-ID: <xmqqk14ze806.fsf@gitster-ct.c.googlers.com>
URL: https://gitlist.dev/e/xmqqk14ze806.fsf%40gitster-ct.c.googlers.com
In-Reply-To: <CAN0heSqoU1NxOtwaE_ZBBzghLXAeC4CxVh1x8R-efOVtbHdA5g@mail.gmail.com>

```
Martin Ågren <martin.agren@gmail.com> writes:

> On Thu, 6 Feb 2020 at 18:54, Han-Wen Nienhuys <hanwen@google.com> wrote:
>> What is the right incantation to do printf of a uint64_t on OSX ?
>>
>> Apparently PRIuMAX is to be used for "uintmax_t", and not for "long
>> long unsigned int".
>
> You could cast it? Grepping around, that seems to be how PRIuMAX is
> used:
>
>   printf("%"PRIuMAX"\n", (uintmax_t)var);

Yup, that is used already in existing code in our codebase, so it is
just as portable as the rest of Git is ;-)

Thanks.

```
