threads / discuss / 52754

Printing a uint64_t portably in Git?

Subject: Printing a uint64_t portably in Git?

## tl;dr

5 messages between Feb 6, 2020 and Feb 6, 2020.

replies: 4people: 3as markdown or json

Han-Wen Nienhuys· Feb 6, 2020, 17:52 UTC · lore
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· Feb 6, 2020, 18:00 UTC · re: Han-Wen Nienhuys · lore

Re: Printing a uint64_t portably in Git?

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· Feb 6, 2020, 19:15 UTC · re: Martin Ågren · lore

Re: Printing a uint64_t portably in Git?

On Thu, Feb 6, 2020 at 7:00 PM Martin Ågren <martin.agren@gmail.com> wrote:
Show 11 quoted lines
>
> 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· Feb 6, 2020, 19:52 UTC · re: Han-Wen Nienhuys · lore

Re: Printing a uint64_t portably in Git?

On Thu, 6 Feb 2020 at 20:15, Han-Wen Nienhuys <hanwen@google.com> wrote:
Show 15 quoted lines
>
> 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· Feb 6, 2020, 21:11 UTC · re: Martin Ågren · lore

Re: Printing a uint64_t portably in Git?

Martin Ågren <martin.agren@gmail.com> writes:
Show 10 quoted lines
> 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.

← back to recent threads