what does __foo means.
Hi all,
Can anyone tell me does double underscore before a function mean? In which scenario a programmer must use it.
Regards,
Krishna Chaitanya
Quoted 6 lines
Hi all,
Can anyone tell me does double underscore before a function mean? In which scenario a programmer must use it.
From the POV of a compiler, _ is like [a-z]. The programmer may use it freely.
Jan Engelhardt
Signature · 1 line
ENOSPC
Quoted 6 lines · Jan Engelhardt
Quoted 4 lines
Hi all,
Can anyone tell me does double underscore before a function mean? In which scenario a programmer must use it.
From the POV of a compiler, _ is like [a-z]. The programmer may use it freely.
Yes, yes, but I don't think that was the question :).
In the kernel a function that begins with __ usually denotes an internal function for that file or subsystem. Not always, but usually.
josh
Quoted 6 lines · Jan Engelhardt
Quoted 4 lines
Hi all,
Can anyone tell me does double underscore before a function mean? In which scenario a programmer must use it.
From the POV of a compiler, _ is like [a-z]. The programmer may use it freely.
Nonsense. The _ is used to provide for a new namespace, __ for a second one. It is common to have a public function 'foo()' which does lots of error checking and has a stable api. foo() in turn calls _foo() to do the actual work, perhaps doing additional checking and verification.
The _namespace is bound by certain rules, some of which apply to the kernel as well. The compiler is free to output symbols in the _Namespace, as well as in the __namespace.
"To get specific, identifiers with two leading underscores are reserved for
the compiler as well as identifiers beginning with a single underscore and using an upper case alphabetic character for the second. "
The linux kernel breaks this by using __ for even more private things.
I don't have K&R handy to check this. We might have some more liberty because we do not link in libc.
Signature · 2 lines
http://www.PowerDNS.com Open source, database driven DNS Software http://lartc.org Linux Advanced Routing & Traffic Control HOWTO
Quoted 10 lines · bert hubert
Nonsense. The _ is used to provide for a new namespace, __ for a second one. It is common to have a public function '
foo()' which does lots of error checking and has a stable api.foo()in turn calls_foo()to do the actual work, perhaps doing additional checking and verification.The
_namespaceis bound by certain rules, some of which apply to the kernel as well. The compiler is free to output symbols in the_Namespace, as well as in the__namespace.
Quoted 5 lines
"To get specific, identifiers with two leading underscores are reserved for
the compiler as well as identifiers beginning with a single underscore and using an upper case alphabetic character for the second. "The linux kernel breaks this by using __ for even more private things.
C99:
"All identifiers that begin with an underscore and either an uppercase letter or another underscore are always reserved for any use."
That applies to normal userspace programs. It allows compiler, libc and possibly the kernel to introduce new identifiers without breaking existing programs. If programs break, it is their fault, they shouldn't have used such identifiers.
The kernel is quite different. Basically, all identifiers belong to the kernel, none to libc/gcc (with very few exceptions). So developers are free to use that at their pleasure and most stick to your description in the first paragraph.
Jörn
Signature · 4 lines
You cannot suppose that Moliere ever troubled himself to be original in the matter of ideas. You cannot suppose that the stories he tells in his plays have never been told before. They were culled, as you very well know. -- Andre-Louis Moreau in Scarabouche