Re: Syntax for partitioning

From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Nikhil Sontakke <nikhil(dot)sontakke(at)enterprisedb(dot)com>
Cc: Itagaki Takahiro <itagaki(dot)takahiro(at)oss(dot)ntt(dot)co(dot)jp>, Marko Tiikkaja <marko(dot)tiikkaja(at)cs(dot)helsinki(dot)fi>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Syntax for partitioning
Date: 2009-11-20 05:56:52
Message-ID: 1258696612.17548.2.camel@vanquo.pezone.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)postgresql(dot)org)
> > To make changes to your subscription:
> > http://www.postgresql.org/mailpref/pgsql-hackers
> >
>
>
>
> --
> http://www.enterprisedb.com
>

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2009-11-20 06:04:43 Re: Python 3.1 support
Previous Message Tom Lane 2009-11-20 05:49:20 Re: Union test case broken in make check?