From: | Kurt Harriman <harriman(at)acm(dot)org> |
---|---|
To: | pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: Mostly Harmless: c++bookends - patch 2 of 4 |
Date: | 2008-12-05 09:16:37 |
Message-ID: | 4938F175.1000400@acm.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
(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.
Attachment | Content-Type | Size |
---|---|---|
c++bookends.patch | text/plain | 2.0 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Kurt Harriman | 2008-12-05 09:18:46 | Re: Mostly Harmless: c++configure - patch 3 of 4 |
Previous Message | Kurt Harriman | 2008-12-05 09:13:37 | Re: Mostly Harmless: c++reserved - patch 1 of 4 |