Re: Syntax for partitioning - Mailing list pgsql-hackers

From Peter Eisentraut
Subject Re: Syntax for partitioning
Date
Msg-id 1258696612.17548.2.camel@vanquo.pezone.net
Whole thread Raw
In response to Re: Syntax for partitioning  (Nikhil Sontakke <nikhil.sontakke@enterprisedb.com>)
List pgsql-hackers
On fre, 2009-11-20 at 11:14 +0530, Nikhil Sontakke wrote:
> Hi,
> 
> >> > partinfo = (PartitionInfo *) malloc(ntups * sizeof(PartitionInfo));
> >
> > 1) Please stop casting the results of palloc and malloc.  We are not
> > writing C++ here.
> >
> 
> I thought it was/is a good C programming practice to typecast (void *)
> always to the returning structure type!!

This could be preferable if you use sizeof on the type, so that you have
an additional check that the receiving variable actually has that type.
But if you use sizeof on the variable itself, it's unnecessary: You just
declare the variable to be of some type earlier, and then the expression
allocates ntups of it, without having to repeat the type information.

> 
> Regards,
> Nikhils
> 
> > 2) I would prefer that you apply sizeof on the variable, not on the
> > type.  That way, the expression is independent of any type changes of
> > the variable, and can be reviewed without having to scroll around for
> > the variable definition.
> >
> > So how about,
> >
> > partinfo = palloc(ntups * sizeof(*partinfo));
> >
> >
> > --
> > Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
> > To make changes to your subscription:
> > http://www.postgresql.org/mailpref/pgsql-hackers
> >
> 
> 
> 
> -- 
> http://www.enterprisedb.com
> 




pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Union test case broken in make check?
Next
From: Simon Riggs
Date:
Subject: Re: Summary and Plan for Hot Standby