Bruno Haible wrote: > Hi John, > >> I'd like to use the filemode module in a C++ file but found that it >> does not have extern "C" magic. I started to submit a patch, but >> stopped when I saw that filemode.h has >> >> # if HAVE_DECL_STRMODE >> # include <string.h> /* FreeBSD, OpenBSD */ >> # include <unistd.h> /* NetBSD */ >> # else >> void strmode (mode_t mode, char *str); >> # endif >> >> void filemodestring (struct stat const *statp, char *str); >> >> and remembered there is a recommendation in the gnulib manual to not >> surround system header files with an extern "C" block. >> >> What's the best way to get declare these two functions extern "C" and >> be consistent with gnulib conventions? > > The best way is to first include all necessary system header files, then, > in an extern "C" block, do all variable or function declarations. > > It is OK to duplicate a #if condition for this purpose. > >> Is it safe to assume that if HAVE_DECL_STRMODE is true, strmode will >> be declared extern "C"? > > Yes. I checked > > MacOS X 10.3 <string.h> > FreeBSD 6.4 <string.h> > OpenBSD 3.8 <string.h> > NetBSD 3.0 <unistd.h> > > and they all look like this: > > __BEGIN_DECLS > ... > void strmode(mode_t, char *); > ... > __END_DECLS > > In general, nowadays, it's rare to find a system function that is _not_ > properly declared inside extern "C" for C++. (Rare example: tcgetsid() > on HP-UX 11.00.) > > Here's a proposed patch. In passing, this patch adds an 'extern' modifier', > which is redundant for functions, but nice to have > - for consistency between variable and function declarations, > - for consistency with the style of the glibc header files, > - for determining the desired set of exported symbols of a shared library > from its include files. > > Jim, OK to commit? > > > 2011-01-14 Bruno Haible <br...@clisp.org> > > filemode: Make function declarations usable in C++ mode. > * lib/filemode.h: Enclose function declarations in extern "C" block. > Reported by John W. Eaton <j...@gnu.org>.
Yes, that looks fine. Thanks, Bruno.