Example 4
In this example, the compiler ignores the visibility attributes of variables m, i, and j, because m and i have internal linkage, and j has no linkage.static int m __attribute__((visibility("protected")));
int n __attribute__((visibility("protected")));
int main(){
int i __attribute__((visibility("protected")));
static int j __attribute__((visibility("protected)));
}
Example 5
In this example, the compiler issues an error message to indicate that you cannot specify two different visibility attributes at the same time in the definition of variable m.//error
int m __attribute__((visibility("hidden"))) __attribute__((visibility("protected")));
Example 6
In this example, the first declaration of function fun() that the compiler processes is extern void fun() __attribute__((visibility("hidden"))), so the visibility attribute of fun() is hidden.extern void fun() __attribute__((visibility("hidden")));
extern void fun() __attribute__((visibility("protected")));
int main(){
fun();
}
Example 7
In this example, the visibility attribute of variable vis_v_ti is default, which is not affected by the setting in the typedef statement.//The -qvisibility=default option is specified.
typedef int __attribute__((visibility("protected"))) INT;
INT vis_v_ti = 1;