Re: Syntax for partitioning
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Nikhil Sontakke <nikhil.sontakke@enterprisedb.com>
Cc: Peter Eisentraut <peter_e@gmx.net>, Itagaki Takahiro <itagaki.takahiro@oss.ntt.co.jp>, Marko Tiikkaja <marko.tiikkaja@cs.helsinki.fi>, pgsql-hackers@postgresql.org
Date: 2009-11-20T06:19:06Z
Lists: pgsql-hackers
Nikhil Sontakke <nikhil.sontakke@enterprisedb.com> writes: >>> 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!! Yes. The above is good style because it ensures that the variable you're assigning the pointer to is the right type to match the sizeof computation. In C++ you'd use operator new instead and still have that type-check without the cast, but indeed we are not writing C++ here. The *real* bug in the quoted code is that it's using malloc. There are a few places in PG where it's appropriate to use malloc not palloc, but pretty darn few. regards, tom lane