11

I was going through the source of some of the standard headers included with gcc (in /usr/include/c++/ ) and found the following at the top of every header:

namespace std _GLIBCXX_VISIBILITY(default)

What exactly is _GLIBCXX_VISIBILITY(default)?

0

1 Answer 1

23

It's a preprocessor macro. And is defined as:

#if _GLIBCXX_HAVE_ATTRIBUTE_VISIBILITY
#define _GLIBCXX_VISIBILITY(V) __attribute__ ((__visibility__ (#V)))
#else
#define _GLIBCXX_VISIBILITY(V) 
#endif

So if _GLIBCXX_HAVE_ATTRIBUTE_VISIBILITY is true then in your case it will expand to:

__attribute__ (( __visibility__ ("default")))

else if _GLIBCXX_HAVE_ATTRIBUTE_VISIBILITY is false it will do nothing.

The __visibility__ attribute is used for defining the visibility of the symbols in a DSO file. Using "hidden" instead of "default" can be used to hide symbols from things outside the DSO.

For example:

__attribute__ ((__visibility__("default"))) void foo();
__attribute__ ((__visibility__("hidden"))) void bar();

The function foo() would be useable from outside the DSO whereas bar() is basically private and can only be used inside the DSO.

You can read a bit more about the __visibility__ attribute here: https://gcc.gnu.org/wiki/Visibility

0

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.