The visibility namespace attribute

The visibility namespace attribute is a language extension that allows you to control whether and how the entities within a namespace defined in one module can be referenced or used in other modules. By using this feature, you can make a shared library smaller and decrease the possibility of symbol collision. For details, see Using visibility attributes.

Read syntax diagramSkip visual syntax diagram
visibility namespace attribute syntax

>>-namespace----identifier----__attribute__--------------------->

>--((--+-visibility-----+--(--+-"default"---+--)--))------------>
       '-__visibility__-'     +-"protected"-+          
                              +-"hidden"----+          
                              '-"internal"--'          

>--{--namespace_body--}----------------------------------------><

You can specify the attribute name visibility with or without leading and trailing double underscore characters; however, using the double underscore characters reduces the likelihood of name conflicts with macros of the same name.

Example

In the following example, function fun() is defined in namespace A , and the visibility attribute of fun() is default:
namespace A __attribute__((visibility("default"))) {
   void fun(){}
}


Voice your opinion on getting help information Ask IBM compiler experts a technical question in the IBM XL compilers forum Reach out to us