Differences between static and visibility hidden

Source: Internet
Author: User

People who do C know that if the defined function is only used in this file, it should be declared as static

But looking at the bionic code in Android, bionic/libc/bionic/pthread. c found such code snippets.

   1269 __LIBC_HIDDEN__   1270 int pthread_mutex_unlock_impl(pthread_mutex_t *mutex)   1271 {   1272     int mvalue, mtype, tid, oldv, shared;   1273    1274     if (__unlikely(mutex == NULL))   1275         return EINVAL;   1276    1277     mvalue = mutex->value;   1278     mtype  = (mvalue & MUTEX_TYPE_MASK);   1279     shared = (mvalue & MUTEX_SHARED_MASK);

Since this function is used by other code in this file, why not define it as static?

    #define __LIBC_HIDDEN__\    __attribute__ ((visibility ("hidden")))

According to the information, the original hidden function is to make the function invisible outside the share libs, that is, there should be other files (units) in the library to use this function.

Search, and found


Pthread_debug.c 451 extern int pthread_mutex_unlock_impl (pthread_mutex_t * mutex );

                        458 return pthread_mutex_unlock_impl(mutex);pthread.c        1270 int pthread_mutex_unlock_impl(pthread_mutex_t *mutex) function 


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.