3

I'm working on a C++ library project. I need to include a platform specific header to get access to some #defines. The catch is, I only want the platform's header visible within my my header. For those including my header, I don't want them to see the additional symbols.

I thought about using a C++ namespace to contain/control the symbol visibility, but it does not work (confer, #define statements within a namespace). And as far as I know, options like --exclude-libs,all only applies to library symbols at link time, and not header symbols.

I also thought about using the symbols I need from the platform header, and then undefining all the symbols it includes. But I don't know how to wildcard #undef platform_header.h/*.

There's a similar question at Including a header file into a header file without exposing it's content to the includer. He's doing it to limit IDE auto-completion, which is producing different answers than I need because of different requirements.

How can I limit the visibility of an included platform header to just my library header?

Community
  • 1
  • 1
jww
  • 97,681
  • 90
  • 411
  • 885
  • 1
    A mechanism to support this, `#scope`, was proposed http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1614.pdf but never got adopted. – Alan Stokes Sep 27 '15 at 11:05

1 Answers1

3

You can't, in general, avoid macro name pollution. The only tool at your disposal is the compiler firewall, to include the C (or just troublesome) header in an implementation file. You then provide your own C++ interface to that, in your header file.

Cheers and hth. - Alf
  • 142,714
  • 15
  • 209
  • 331