I have Sybase ASE CPRE Embedded SQL С code:
void MyFunc( MyClass*unit_address )
{
EXEC SQL BEGIN DECLARE SECTION;
CS_BINARY var1[sizeof(MyClass)];
EXEC SQL END DECLARE SECTION;
}
Try to migrate to PostgreSQL ECPG Embedded SQL С code:
void MyFunc( MyClass*unit_address )
{
EXEC SQL BEGIN DECLARE SECTION;
unsigned char var1[sizeof(MyClass)];
EXEC SQL END DECLARE SECTION;
}
But ecpg.exec pre-compiler returns:
d:\>"c:\Program Files\PostgreSQL\9.3\bin\ecpg.exe"-o 1.c 1.pgc
1.pgc: 4: ERROR: syntax error at or near "("
error deleting output file "1.c"
My solution:
void MyFunc( MyClass*unit_address )
{
#define VAR1_SIZEOF sizeof(MyClass)
EXEC SQL BEGIN DECLARE SECTION;
unsigned char var1[VAR1_SIZEOF];
EXEC SQL END DECLARE SECTION;
#undef VAR1_SIZEOF
}
C code of function after pre-compile:
void MyFunc( MyClass*unit_address )
{
#define VAR1_SIZEOF sizeof(MyClass)
/* exec sql begin declare section */
#line 1 "1.pgc"
void MyFunc( MyClass*unit_address )
{
#define VAR1_SIZEOF sizeof(MyClass)
/* exec sql begin declare section */
#line 5 "1.pgc"
unsigned char var1 [ VAR1_SIZEOF ] ;
/* exec sql end declare section */
#line 6 "1.pgc"
#undef VAR1_SIZEOF
}
but perhaps there is a more correct decision.