Re: MemSetLoop ignoring the 'val' parameter - Mailing list pgsql-hackers

From Tom Lane
Subject Re: MemSetLoop ignoring the 'val' parameter
Date
Msg-id 9249.1349738756@sss.pgh.pa.us
Whole thread Raw
In response to Re: MemSetLoop ignoring the 'val' parameter  (Andres Freund <andres@2ndquadrant.com>)
List pgsql-hackers
Andres Freund <andres@2ndquadrant.com> writes:
> On Tuesday, October 09, 2012 12:56:16 AM Tom Lane wrote:
>> Andres Freund <andres@2ndquadrant.com> writes:
>>> The 'val' parameter is ignored.

>> This is not broken.  Read the comments for MemSetTest.

> Ah. I was surprised about that already. The comment says that val has to be 
> constant though, not that it has to be zero. In my understanding 1 is constant 
> as well. Also, why do we even pass in a 'val' parameter in that case?

Well, first off, the callers should not be aware of the detail that
MemSetTest insists on a val of zero, so they have to pass val even
though it's unused by the current implementation of MemSetLoop.

The callers are responsible for not passing a volatile value there, but
it's hard to dodge that problem given that we're dealing with macros;
if the value changes on repeat evaluation we're screwed anyway.

However, "nonvolatile" is not "constant".  For instance, it's perfectly
fine to pass MemSetTest/Loop a variable for the "val" that is sometimes
zero and sometimes not.  If we changed the coding as you suggest, the
compiler would probably generate less efficient code since it wouldn't
realize (unless it was quite smart) that MemSetLoop is always filling
with zeroes.
        regards, tom lane



pgsql-hackers by date:

Previous
From: Jim Nasby
Date:
Subject: Re: PQping command line tool
Next
From: Jim Nasby
Date:
Subject: Re: Deparsing DDL command strings