Re: C function woes - Mailing list pgsql-general

From Peter Eisentraut
Subject Re: C function woes
Date
Msg-id Pine.LNX.4.30.0102211735230.1381-100000@peter.localdomain
Whole thread Raw
In response to Re: C function woes  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: C function woes
List pgsql-general
Tom Lane writes:

> text *
> hello()
>  {
>         char data[] = "hello world";
>         int32 new_text_size = VARHDRSZ + sizeof(data);
>         text *new_text = (text *) palloc(new_text_size);
>
>     VARSIZE(new_text) = new_text_size;
>         memcpy(VARDATA(new_text), data, sizeof(data));
>         return new_text;
>  }

Is it good practice to scribble around in data type internals?  Why not

text *
hello()
{
    return textin("hello world");
}

--
Peter Eisentraut      peter_e@gmx.net       http://yi.org/peter-e/


pgsql-general by date:

Previous
From: "And. Andruikhanov"
Date:
Subject: ELOG_TIMESTAMPS feature
Next
From: "Gregory Wood"
Date:
Subject: Re: Deferred NOT NULL?