Re: Use of PRId64 with PostgreSQL functions

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Paragon Corporation" <lr(at)pcorp(dot)us>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Use of PRId64 with PostgreSQL functions
Date: 2015-07-31 21:23:11
Message-ID: 15982.1438377791@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

"Paragon Corporation" <lr(at)pcorp(dot)us> writes:
> I've been currently suffering an issue in mingw64 with changes made in
> PostGIS topology code base. Sadly it only happens to me (compiling in
> mingw64)

> Issue is when code like this was introduced
> appendStringInfo(str, "%s%" PRId64, sep, edge->start_node);

> Which uses a PostgreSQL function appendStringInfo - as noted here:
> https://trac.osgeo.org/postgis/ticket/3206

Huh. Apparently, whichever Windows compiler you're using defines
PRId64 as "d", which surely seems pretty broken.

> I noticed a thread in March on pgsql-hackers that discussed int limits
> http://www.postgresql.org/message-id/20150331141423.GK4878@alap3.anarazel.de
> in PostgreSQL and Andres Freund made this comment which stuck in my head:
> " for another we'd need some uglyness to determine the
> correct printf modifier for int64_t (can't use PRId64 etc afaics)."
> What exactly did he mean by can't use PRId64?

That was about the fact that we don't know whether PRId64 is defined
as "ld" or "lld" on machines where either of those could legitimately
mean a 64-bit int. (And while either would work at runtime in that
case, we'd get compiler warnings we don't want if we chose the wrong
one.) That problem doesn't apply to Windows AFAIK.

However, some googling suggests that PRId64 isn't defined on all Windows
build environments, and your report says that there's at least one such
environment where it is defined, but wrongly :-(. So that's yet another
good reason to stay away from PRId64. You'll notice that it appears
nowhere in the Postgres sources.

You did not say how you're declaring the variable that's being printed
here, but if it's based on the int64 type declared by c.h, you should
use the INT64_FORMAT or INT64_MODIFIER strings declared by c.h/pg_config.h.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Heikki Linnakangas 2015-07-31 21:46:53 Re: 64-bit XIDs again
Previous Message Alvaro Herrera 2015-07-31 21:04:35 Re: Use of PRId64 with PostgreSQL functions