I am currently studying the flow of u-boot for ARM. I find many functions with this format __funcname__
. Why are 2 underscores used before and after a file name?
Asked
Active
Viewed 211 times
1

Parth Shah
- 573
- 1
- 6
- 17
-
2Because the programmer who implemented the functions added two underscores before and after its name. – Oct 31 '12 at 06:53
-
Just a naming convention the author prefers. – Alok Save Oct 31 '12 at 06:54
-
2Actually they are reserved for implementation, check this out http://stackoverflow.com/questions/1449181/what-does-double-underscore-const-mean-in-c – imreal Oct 31 '12 at 06:57
-
@H2CO3 and Als: Please do refer the link shared by Nick. I fear you have misunderstood it. – Parth Shah Oct 31 '12 at 07:02
-
@ParthShah I fear you didn't get the light sarcasm in that comment of mine. I have read tons of papers like this, and after several years of C programming on various POSIX systems, I'm naturally aware of identifiers beginning with underscores being reserved by the implementation. – Oct 31 '12 at 07:17
2 Answers
3
It is supposed to indicate that the function is used in system level code. I believe in some compilers, they are treated differently than normal functions. I don't think it is really a requirement, but I think it was something that used to be done, and the tradition is either carried on, or you are looking at some older code maybe.

Kiith Nabaal
- 366
- 2
- 5
- 16
3
Keywords that start with two leading underscores or a leading underscore followed by a capital letter are reserved. They can be used by the standard library and also the operating system. This way these functions won't clash with the names of functions in userspace (and if they do then it's the user's fault as those names are resereved!)

dave
- 4,812
- 4
- 25
- 38
-
+1 assuming this is C or C++ we're talking about. IIRC the standards define some special `__whatever__` symbols, and most compilers define plenty more - e.g. preprocessor symbols such as `__GNUC__` and built-in functions such as `__builtin_popcount` (count number of set bits). But there's also a lot more symbols like that that you're just not supposed to know about unless you're maintaining the libraries for that compiler. – Oct 31 '12 at 07:04