Re: Syntax for partitioning

Поиск
Список
Период
Сортировка
От Peter Eisentraut
Тема Re: Syntax for partitioning
Дата
Msg-id 1258696612.17548.2.camel@vanquo.pezone.net
обсуждение исходный текст
Ответ на Re: Syntax for partitioning  (Nikhil Sontakke <nikhil.sontakke@enterprisedb.com>)
Список 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 по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Union test case broken in make check?
Следующее
От: Simon Riggs
Дата:
Сообщение: Re: Summary and Plan for Hot Standby