John W. Eaton wrote: > If I add "using gnulib::open;" inside the "#ifdef __cplusplus" block, > ... > then I don't even have to prefix all of the uses of open in my code > with gnulib::. This seems like the best solution for me.
A good idea. Unfortunately I cannot see how to make it work: This program ================================ foo.cc =============================== #include <fcntl.h> extern "C" { extern int rpl_open (const char *filename, int flags, ...) __attribute__ ((__nonnull__ (1))); } namespace gnulib { int (*const open) (const char *filename, int flags, ...) = rpl_open; } class foo { int open (const char *arg); }; int bar_uses_global () { return open ("/dev/null", O_RDWR); } // Does not work, leads to // error: reference to ‘open’ is ambiguous // /usr/include/fcntl.h:85: error: candidates are: int open(const char*, int, ...) // foo.cc:9: error: int (* const gnulib::open)(const char*, int, ...) //using namespace gnulib; int bar_uses_gnulib () { return gnulib::open ("/dev/null", O_RDWR); } // John Eaton suggests this. using gnulib::open; int bar_uses_gnulib_implicitly () { return open ("/dev/null", O_RDWR); } // Compatibility with future C++1X: namespace posix = gnulib; int bar_uses_gnulib_via_posix () { return posix::open ("/dev/null", O_RDWR); } ======================================================================= gives an error (on a glibc system with gcc 4.3.1): $ g++ -S foo.cc foo.cc:31: error: ‘open’ is already declared in this scope And when I change the first line to namespace system { #include <fcntl.h> } using namespace system; then there is a different error message: $ g++ -S foo.cc foo.cc: In function ‘int bar_uses_gnulib_implicitly()’: foo.cc:37: error: reference to ‘open’ is ambiguous foo.cc:12: error: candidates are: int (* const gnulib::open)(const char*, int, ...) /usr/include/fcntl.h:85: error: int system::open(const char*, int, ...) foo.cc:37: error: reference to ‘open’ is ambiguous foo.cc:12: error: candidates are: int (* const gnulib::open)(const char*, int, ...) /usr/include/fcntl.h:85: error: int system::open(const char*, int, ...) Do you see a way to make it work? Bruno