C question about bitmasks in datetime.c

Started by Bruce Momjianover 12 years ago3 messageshackers
Jump to latest
#1Bruce Momjian
bruce@momjian.us

I see a few cases of this code in src/backend/utils/adt/datetime.c:

else if ((fmask & DTK_DATE_M) != DTK_DATE_M)

Wouldn't this be clearer as:

else if (fmask & DTK_DATE_M)

--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#2Andres Freund
andres@anarazel.de
In reply to: Bruce Momjian (#1)
Re: C question about bitmasks in datetime.c

On 2013-10-01 11:15:36 -0400, Bruce Momjian wrote:

I see a few cases of this code in src/backend/utils/adt/datetime.c:

else if ((fmask & DTK_DATE_M) != DTK_DATE_M)

Wouldn't this be clearer as:

else if (fmask & DTK_DATE_M)

That doesn't have the same meaning. The latter is trueif only one bit of
DTK_DATE_M is set, while the former requires all bits to be set.

Greetings,

Andres Freund

--
Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#3Bruce Momjian
bruce@momjian.us
In reply to: Andres Freund (#2)
Re: C question about bitmasks in datetime.c

On Tue, Oct 1, 2013 at 05:17:35PM +0200, Andres Freund wrote:

On 2013-10-01 11:15:36 -0400, Bruce Momjian wrote:

I see a few cases of this code in src/backend/utils/adt/datetime.c:

else if ((fmask & DTK_DATE_M) != DTK_DATE_M)

Wouldn't this be clearer as:

else if (fmask & DTK_DATE_M)

That doesn't have the same meaning. The latter is trueif only one bit of
DTK_DATE_M is set, while the former requires all bits to be set.

Oh, I see it now --- DTK_DATE_M is not a bit but rather a set of bits,
and they are testing if _all_ are set. Thank you!

--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers