(Re-sending just the second of four patches: c++bookends)
These patches are based on CVS head in which the latest commit was
user: petere
date: Thu Dec 04 17:51:28 2008 +0000
summary: Default values for function arguments
2. c++bookends
C++ code can call C functions and share global variables with C,
provided those declarations are surrounded by "bookends":
extern "C" {
...
};
Header files can be made bilingual, to declare interfaces which
look the same to both C and C++ callers. This is done by
placing C++ bookends within the header file, guarded by #ifdefs
#ifdef __cplusplus
extern "C" {
#endif
...
#ifdef __cplusplus
}; /* extern "C" */
#endif
This way the C++ caller can just #include the header file without
worrying whether the interface is implemented in C or C++.
Usually, extension modules written in C++ will put bookends around
all of their PostgreSQL #includes.
However, "postgres.h" usually stands alone as the first #include,
followed by some system #includes, and then the rest of the
PostgreSQL #includes. It is much nicer if a C++ file has just one
pair of bookends around its main block of PostgreSQL #includes.
This patch gives postgres.h its own internal bookends, making it
bilingual, so that its #include can continue to stand alone at the
head of each file.
Just a few additional header files are mentioned in the PostgreSQL
Reference Manual for add-on developers to use: fmgr.h, funcapi.h,
and spi.h. This patch adds bookends within those three files for
the benefit of beginners writing very simple extensions in C++.
Documentation and learning are simplified because C example code
can be compiled as C or C++ without change.
diff -r 55d732d0fbcd src/include/executor/spi.h
--- a/src/include/executor/spi.h
+++ b/src/include/executor/spi.h
@@ -18,6 +18,10 @@
* included postgres.h
*/
#include "postgres.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
/*
* Most of these are not needed by this file, but may be used by
@@ -156,4 +160,8 @@
extern void AtEOXact_SPI(bool isCommit);
extern void AtEOSubXact_SPI(bool isCommit, SubTransactionId mySubid);
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
#endif /* SPI_H */
diff -r 55d732d0fbcd src/include/fmgr.h
--- a/src/include/fmgr.h
+++ b/src/include/fmgr.h
@@ -17,6 +17,10 @@
*/
#ifndef FMGR_H
#define FMGR_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
/* We don't want to include primnodes.h here, so make a stub reference */
typedef struct Node *fmNodePtr;
@@ -544,4 +548,8 @@
*/
extern char *fmgr(Oid procedureId,...);
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
#endif /* FMGR_H */
diff -r 55d732d0fbcd src/include/funcapi.h
--- a/src/include/funcapi.h
+++ b/src/include/funcapi.h
@@ -16,11 +16,14 @@
#ifndef FUNCAPI_H
#define FUNCAPI_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
#include "fmgr.h"
#include "access/tupdesc.h"
#include "executor/executor.h"
#include "executor/tuptable.h"
-
/*-------------------------------------------------------------------------
* Support to ease writing Functions returning composite types
@@ -299,4 +302,8 @@
PG_RETURN_NULL(); \
} while (0)
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
#endif /* FUNCAPI_H */
diff -r 55d732d0fbcd src/include/postgres.h
--- a/src/include/postgres.h
+++ b/src/include/postgres.h
@@ -44,7 +44,12 @@
#ifndef POSTGRES_H
#define POSTGRES_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
#include "c.h"
+
#include "utils/elog.h"
#include "utils/palloc.h"
@@ -693,4 +698,8 @@
const char *errorType,
const char *fileName, int lineNumber);
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
#endif /* POSTGRES_H */
--
Sent via pgsql-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers