9

Possible Duplicate:
Why do people use __(double underscore) so much in C++

I was studying the Linux kernel programming code.

There are some data structures and functions which start with a double underscore like:

__u32  len

How is that different from normal variables?

Community
  • 1
  • 1
  • http://stackoverflow.com/questions/224397/why-do-people-use-double-underscore-so-much-in-c – 3Dave Jul 24 '10 at 16:18
  • 1
    Disagree with duplicate because this is about the *Linux kernel*, which is C and not C++, and in some points is a world of it's own. – Ciro Santilli OurBigBook.com Oct 24 '15 at 13:59
  • Look at http://stackoverflow.com/a/224420/1657476 "The use of two underscores (`__') in identifiers is reserved for the compiler's internal use according to the **ANSI-C standard**." – Meirion Hughes Feb 20 '16 at 16:41

3 Answers3

17

It means it's a system-reserved name. The C standard says that all names beginning with two underscore, or underscore and capital letter, are reserved for the use of the system or compiler and should not be defined in application code.

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
  • If it should not be allowed, then why is it available for use? By system, do you mean operating system? – Dean P Jul 17 '17 at 14:02
3

The other answers are correct that it's reserved for the implementation. Of course here Linux should advance out of the 20th century and use the standard type uint32_t rather than the myriad of nonstandard names (__u32, u_int32_t, ...) that plagued legacy Unices..

R.. GitHub STOP HELPING ICE
  • 208,859
  • 35
  • 376
  • 711
  • Those types are defined in exactly the same way they are defined by the standard library headers (stdint.h). Why is it such a big deal if a) they're the same type and b) they're not exported for usage by userspace programs? – Michael Foukarakis Jul 24 '10 at 16:59
  • @mfukar Consistency is important from a maintenance standpoint. Using ten different names for the same type not only introduces potential compatibility problems, (say, using specific long, uint, etc types mixed with generic int, the size of which is platform-dependent), it decreases code readability. – 3Dave Jul 24 '10 at 17:10
  • 1
    I tried to understnad the kernel c code but its going over my head. i think i have less understanding with pointers or pointer function inside structures. is there any C book where i can study those topics separately so that i can then read the kernel code. –  Jul 24 '10 at 17:32
  • I understand where you're coming from. Such ill-considerate cases of type intermixing are rather rare in the linux kernel, I'd dare say. Of course, you'll find the `unsigned long`s all over the syscall implementations; but it doesn't really matter, it's by definition a platform-specific chunk of code, and replacing it with the type with appropriate storage space doesn't help anybody. Also, remember that there's a bunch of people arguing against the use of C99 types in favour of Linux types. I don't know what's up with that. :-) – Michael Foukarakis Jul 24 '10 at 17:35
1

That's a type, defined in here (as well as few other places).

It is by convention that usually a double underscore in front of a type, variable or function name implies a name that is always reserved, as defined in section 7.1.3 of the current standard (C99).

Michael Foukarakis
  • 39,737
  • 6
  • 87
  • 123