Why assignment before return?

From: Magnus Hagander <magnus(at)hagander(dot)net>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Why assignment before return?
Date: 2010-08-20 11:46:48
Message-ID: AANLkTiny6rSOaTsvRLbzF=_vC4TNGGJu-f8p5H+dAb6H@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

This code-pattern appears many times in pgstatfuncs.c:

Datum
pg_stat_get_blocks_fetched(PG_FUNCTION_ARGS)
{
Oid relid = PG_GETARG_OID(0);
int64 result;
PgStat_StatTabEntry *tabentry;

if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
result = 0;
else
result = (int64) (tabentry->blocks_fetched);

PG_RETURN_INT64(result);
}

Why do we assign this to "result" and then return, why not just:
if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
PG_RETURN_INT64(0);
else
PG_RETURN_INT64(tabentry->blocks_fetched);

--
 Magnus Hagander
 Me: http://www.hagander.net/
 Work: http://www.redpill-linpro.com/

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Max Bowsher 2010-08-20 11:50:32 Re: git: uh-oh
Previous Message Magnus Hagander 2010-08-20 11:02:00 Re: git: uh-oh