Can I use extern "C" in an extension so I can use C++? - Mailing list pgsql-hackers

From Isaac Morland
Subject Can I use extern "C" in an extension so I can use C++?
Date
Msg-id CAMsGm5eOg-SaWKSHkytAnQ_YqfXf2nKxrs=H_Q1XGKcdaGh2DQ@mail.gmail.com
Whole thread Raw
Responses Re: Can I use extern "C" in an extension so I can use C++?  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
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.

The C++ compiler is mangling the names so they aren't visible to the extension mechanism. The following page suggests using extern C (it doesn't specify that this means extern "C", but I suppose anybody who actually knew what they were doing would have known that immediately):


So I'm writing my functions to start:

extern "C" Datum ...

The problem is that PG_FUNCTION_INFO_V1 generates its own function declaration with a conflicting extern specification (just plain extern, which I guess means "C++" in the context of C++ code).

I also tried wrapping everything - both the functions and the PG_FUNCTION_INFO_V1 invocations - in extern "C" { ... }, but now a variable declaration from fmgr.h conflicts with one from the macros.

Is there a simple fix I'm missing? Any hints much appreciated.

pgsql-hackers by date:

Previous
From: Daniel Gustafsson
Date:
Subject: Re: vacuum verbose detail logs are unclear; log at *start* of each stage
Next
From: Daniel Gustafsson
Date:
Subject: Re: Online checksums verification in the backend