Thread: failed to compile a C++ SPI function

failed to compile a C++ SPI function

From
Louis-David Mitterrand
Date:
Just for fun I changed the extension of my SPI function and trigger
source file from .c to .C and tried to compile it:

> g++ -g -Wall -I /usr/include/postgresql -fPIC -pedantic    -c -o bid_control.o bid_control.C
> In file included from /usr/include/postgresql/nodes/relation.h:18,
>                  from /usr/include/postgresql/executor/spi.h:18,
>                  from bid_control.h:31,
>                  from bid_control.C:21:
> /usr/include/postgresql/nodes/parsenodes.h:871: parse error before `typename'

It seems the "typename" word used in the following structure is a
reserved word in C++. (and is appears colored like a type in Vim)

> /*
>  * ParamNo - specifies a parameter reference
>  */
> typedef struct ParamNo
> {
>     NodeTag     type;
>     int         number;         /* the number of the parameter */
>     TypeName   *typename;       /* the typecast */                 ^^^^^^^^^
>     List       *indirection;    /* array references */
> } ParamNo;

Is it totally unreasonable try C++ in SPI programming?

Cheers,


-- 
Louis-David Mitterrand - ldm@apartia.org - http://www.apartia.org

Isn't vi that text editor with two modes... one that beeps and one
that corrupts your file?" -- Dan Jocabson, on comp.os.linux.advocacy


Re: failed to compile a C++ SPI function

From
Bruce Momjian
Date:
I am willing to change it to typname.  Any comments?

> Just for fun I changed the extension of my SPI function and trigger
> source file from .c to .C and tried to compile it:
> 
> > g++ -g -Wall -I /usr/include/postgresql -fPIC -pedantic    -c -o bid_control.o bid_control.C
> > In file included from /usr/include/postgresql/nodes/relation.h:18,
> >                  from /usr/include/postgresql/executor/spi.h:18,
> >                  from bid_control.h:31,
> >                  from bid_control.C:21:
> > /usr/include/postgresql/nodes/parsenodes.h:871: parse error before `typename'
> 
> It seems the "typename" word used in the following structure is a
> reserved word in C++. (and is appears colored like a type in Vim)
> 
> > /*
> >  * ParamNo - specifies a parameter reference
> >  */
> > typedef struct ParamNo
> > {
> >     NodeTag     type;
> >     int         number;         /* the number of the parameter */
> >     TypeName   *typename;       /* the typecast */
>                   ^^^^^^^^^
> >     List       *indirection;    /* array references */
> > } ParamNo;
> 
> Is it totally unreasonable try C++ in SPI programming?
> 
> Cheers,
> 
> 
> -- 
> Louis-David Mitterrand - ldm@apartia.org - http://www.apartia.org
> 
> Isn't vi that text editor with two modes... one that beeps and one
> that corrupts your file?" -- Dan Jocabson, on comp.os.linux.advocacy
> 


--  Bruce Momjian                        |  http://candle.pha.pa.us pgman@candle.pha.pa.us               |  (610)
853-3000+  If your life is a hard drive,     |  830 Blythe Avenue +  Christ can be your backup.        |  Drexel Hill,
Pennsylvania19026
 


Re: failed to compile a C++ SPI function

From
Tom Lane
Date:
Bruce Momjian <pgman@candle.pha.pa.us> writes:
> I am willing to change it to typname.  Any comments?

That's hardly the only change you will have to make to get the headers
to pass through a C++ compiler without complaint.  How many existing
applications do you want to risk breaking?

ParamNo probably isn't a widely used node type, but there are four
structs with fields named 'typename' and one with a field named 'class'
just in parsenodes.h.

I think that before we start making changes with C++ cleanness as a
goal, we should try to get a precise idea of the extent of the changes
that would be needed, and then estimate how much user code might
reference the fields we'd need to rename.
        regards, tom lane


Re: failed to compile a C++ SPI function

From
Bruce Momjian
Date:
> Bruce Momjian <pgman@candle.pha.pa.us> writes:
> > I am willing to change it to typname.  Any comments?
> 
> That's hardly the only change you will have to make to get the headers
> to pass through a C++ compiler without complaint.  How many existing
> applications do you want to risk breaking?
> 
> ParamNo probably isn't a widely used node type, but there are four
> structs with fields named 'typename' and one with a field named 'class'
> just in parsenodes.h.
> 
> I think that before we start making changes with C++ cleanness as a
> goal, we should try to get a precise idea of the extent of the changes
> that would be needed, and then estimate how much user code might
> reference the fields we'd need to rename.

Agreed.

--  Bruce Momjian                        |  http://candle.pha.pa.us pgman@candle.pha.pa.us               |  (610)
853-3000+  If your life is a hard drive,     |  830 Blythe Avenue +  Christ can be your backup.        |  Drexel Hill,
Pennsylvania19026