Re: pgsql: Fix pg_size_bytes() to be more portable. - Mailing list pgsql-committers

From Tom Lane
Subject Re: pgsql: Fix pg_size_bytes() to be more portable.
Date
Msg-id 10663.1455985971@sss.pgh.pa.us
Whole thread Raw
In response to Re: pgsql: Fix pg_size_bytes() to be more portable.  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: pgsql: Fix pg_size_bytes() to be more portable.  (Dean Rasheed <dean.a.rasheed@gmail.com>)
List pgsql-committers
After further thought about the portability implications of this ---

1. We probably gave up support for long-long-less compilers when we agreed
to start requiring a working int64 type.  On a 32-bit machine that's
highly likely to be "long long", and 64-bit machines are mostly new enough
that they'd have C99-compliant compilers.

2. Nonetheless, LL is not the same as int64; on modern 64-bit machines it
probably means int128.  So the right thing to do when writing a constant
you mean to be int64 is to use a cast or [U]INT64CONST().  (You need that
macro if the constant value might be too wide for plain int, since pickier
compilers may reject an unsuffixed constant wider than int.)

Your updated code looks fine from here.  I looked into changing that code
in ecpg, but it would be more invasive than I thought because ecpg doesn't
use c.h.  Some rearrangement of the ecpg headers would be required, and
in view of point #1, it's unlikely to be worth it; it might buy a bit of
micro-efficiency but not much.

            regards, tom lane


pgsql-committers by date:

Previous
From: Joe Conway
Date:
Subject: Re: pgsql: Add pg_size_bytes() to parse human-readable size strings.
Next
From: Dean Rasheed
Date:
Subject: Re: pgsql: Fix pg_size_bytes() to be more portable.