On Fri, Apr 01, 2005 at 11:21:24PM -0500, Tom Lane wrote:
>
> There's nothing obviously wrong in what you posted ... other than the
> very poor style of misspelling "VARHDRSZ" as "4", not using VARDATA and
> VARATT_SIZEP macros, and generally doing your best to ignore every one
> of the portability conventions that are built into the Postgres
> sources.
Do you recommend always using the macros, even if the data is a
structure? For example, I've done things like the following:
typedef struct foo
{
int32 size;
int32 numitems;
float8 item[1];
} foo;
and then
foo *p;
size = sizeof(*p) + (numitems - 1) * sizeof(p->item);
p = palloc(size);
p->size = size;
p->numitems = numitems;
for (i = 0; i < numitems; ++i)
p->item[i] = /* some value */;
I see similar code in arrayfuncs.c. Is this style safe, or would
you suggest changing the code to use the macros?
--
Michael Fuhr
http://www.fuhr.org/~mfuhr/