Received: from sss.pgh.pa.us (sss.pgh.pa.us [209.114.132.154] (may be forged)) by hub.org (8.10.1/8.10.1) with ESMTP id e8M26Ss62546 for ; Thu, 21 Sep 2000 22:06:29 -0400 (EDT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.11.0/8.11.0) with ESMTP id e8M26RB25785 for ; Thu, 21 Sep 2000 22:06:27 -0400 (EDT) To: pgsql-sql@hub.org Subject: Re: C functions and int8? In-reply-to: <67alssorhjla484lck04khhju83h6g4aji@4ax.com> References: <67alssorhjla484lck04khhju83h6g4aji@4ax.com> Comments: In-reply-to Forest Wilkinson message dated "Thu, 21 Sep 2000 17:35:27 -0700" Date: Thu, 21 Sep 2000 22:06:27 -0400 Message-ID: <25782.969588387@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200009/180 Forest Wilkinson writes: > That's an int8 meaning "eight bit integer". I want to work with an int8 > meaning "64 bit integer", as described in the docs: > http://www.postgresql.org/users-lounge/docs/7.0/user/datatype.htm#AEN942 > So how do I return one of these suckers from a C function? Emulate the code in src/backend/utils/adt/int8.c. Currently this involves palloc'ing an int8, setting it, and returning a pointer to it. For instance, int8 addition is int64 * int8pl(int64 *val1, int64 *val2) { int64 *result = palloc(sizeof(int64)); if ((!PointerIsValid(val1)) || (!PointerIsValid(val2))) return NULL; *result = *val1 + *val2; return result; } In 7.1 it'll be a lot cleaner (IMNSHO anyway ;-)): Datum int8pl(PG_FUNCTION_ARGS) { int64 val1 = PG_GETARG_INT64(0); int64 val2 = PG_GETARG_INT64(1); PG_RETURN_INT64(val1 + val2); } which actually does about the same things under the hood, but you don't have to sully your hands with 'em ... regards, tom lane