Meaning of double underscore in the beginning

pythonic picture pythonic · May 21, 2012 · Viewed 12k times · Source

In the standard library (glibc) I see functions defined with leading double underscores, such as __mmap in sys/mman.h. What is the purpose? And how can we still call a function mmap which doesn't seem to be declared anywhere. I mean we include sys/mman.h for that, but sys/mman.h doesn't declare mmap, it declares only __mmap.

Answer

dirkgently picture dirkgently · May 21, 2012

From GNU's manual:

In addition to the names documented in this manual, reserved names include all external identifiers (global functions and variables) that begin with an underscore (‘_’) and all identifiers regardless of use that begin with either two underscores or an underscore followed by a capital letter are reserved names. This is so that the library and header files can define functions, variables, and macros for internal purposes without risk of conflict with names in user programs.

This is a convention which is also used by C and C++ vendors.