Обсуждение: A couple more PostgreSQL C questions
I have a couple of more PostgreSQL C questions, about the following two compiler warnings: ____________________________________________________ warning: ISO C90 forbids mixed declarations and code This appears to be caused by the following statement: text* rand_dev = PG_GETARG_TEXT_P(0); in the following context PG_FUNCTION_INFO_V1( y_somefunc ); Datum y_somefunc ( PG_FUNCTION_ARGS ) { if( PG_ARGISNULL(0) || PG_ARGISNULL(1) || PG_ARGISNULL(2) ) { PG_RETURN_NULL(); } text* rand_dev = PG_GETARG_TEXT_P(0); ... Should I be concerned by this? What's the proper way to code this? _________________________________________________________________________________ warning: passing argument 3 of 'GetAttributeByNum' from incompatible pointer type ...caused by the following: bool isNull; ... n = GetAttributeByNum( tup, 0, &isNull ); executor.h has: /* * prototypes from functions in execQual.c */ extern Datum GetAttributeByNum(HeapTupleHeader tuple, AttrNumber attrno, bool *isNull); I'm just not seeing what's wrong here... -- Ron Peterson https://www.yellowbank.com/
On Tue, Nov 07, 2006 at 07:50:52PM -0500, Ron Peterson wrote: > I have a couple of more PostgreSQL C questions, about the following two > compiler warnings: > > warning: ISO C90 forbids mixed declarations and code I'm thinking this is unavoidable, and unless my time machine starts working, irrelevant. I'm thinking the correct answer is "just live with it until your version of gcc uses c99 as the default standard". > warning: passing argument 3 of 'GetAttributeByNum' from incompatible pointer type > > bool isNull; src/include/c.h has typedef char bool; which was conflicting with the definition of bool from elsewhere. I just did my own typdef char pg_bool and used that. -- Ron Peterson https://www.yellowbank.com/
Ron Peterson <ron.peterson@yellowbank.com> writes: > Datum > y_somefunc ( PG_FUNCTION_ARGS ) > { > if( PG_ARGISNULL(0) || > PG_ARGISNULL(1) || > PG_ARGISNULL(2) ) > { > PG_RETURN_NULL(); > } > text* rand_dev = PG_GETARG_TEXT_P(0); > ... > Should I be concerned by this? What's the proper way to code this? The proper way to code that is either { text* rand_dev; if( PG_ARGISNULL(0) || PG_ARGISNULL(1) || PG_ARGISNULL(2) ) { PG_RETURN_NULL(); } rand_dev = PG_GETARG_TEXT_P(0); ... or probably better, declare the function STRICT and drop the runtime ARGISNULL tests entirely. > I'm thinking the correct answer is "just live with > it until your version of gcc uses c99 as the default standard". Declarations in the middle of a code block are C++, not C; if you try to hold your breath until your C compiler accepts it, you will die. regards, tom lane