Re: Can I use extern "C" in an extension so I can use C++?

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Can I use extern "C" in an extension so I can use C++?
Дата
Msg-id 1313823.1593986827@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Can I use extern "C" in an extension so I can use C++?  (Isaac Morland <isaac.morland@gmail.com>)
Ответы Re: Can I use extern "C" in an extension so I can use C++?  (Isaac Morland <isaac.morland@gmail.com>)
Список pgsql-hackers
Isaac Morland <isaac.morland@gmail.com> writes:
> I'm writing a small extension, and I'm trying to use C++ constructs. I'm
> not actually doing anything that needs C++, but I *really* like declaring
> variables when I first initialize them (for example), and I also *really*
> like warning-free compiles.

Well, you could get that with -Wno-declaration-after-statement ...
but yeah, this is supposed to work, modulo all the caveats on the
page you already found.

> The C++ compiler is mangling the names so they aren't visible to the
> extension mechanism.

Something like the attached works for me; what problem are you having
*exactly*?

$ g++ -Wall -fno-strict-aliasing -fwrapv -g -O2 -D_GNU_SOURCE -c -I/home/postgres/pgsql/src/include -o test.o test.cpp
$ nm --ext --def test.o
0000000000000000 T Pg_magic_func
0000000000000010 T pg_finfo_silly_func
0000000000000020 T silly_func

            regards, tom lane

extern "C" {

#include "postgres.h"

#include "fmgr.h"

PG_MODULE_MAGIC;

PG_FUNCTION_INFO_V1(silly_func);

}

extern "C" Datum
silly_func(PG_FUNCTION_ARGS)
{
    char       *str = PG_GETARG_CSTRING(0);

    PG_RETURN_INT32(strlen(str));
}

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Daniel Gustafsson
Дата:
Сообщение: Re: Binary support for pgoutput plugin
Следующее
От: Isaac Morland
Дата:
Сообщение: Re: Can I use extern "C" in an extension so I can use C++?