Hi just wondering what use the underscore symbol has for example...
is there a reason why the variables begin with an underscore?Code:_device->SetIndices( _ib );
Hi just wondering what use the underscore symbol has for example...
is there a reason why the variables begin with an underscore?Code:_device->SetIndices( _ib );
From the compilers perspective, _ is just like a..z, A..Z - you can use it anywhere in a variable name.
However, there are some rules in the C compiler implementors guides that says that symbols starting with one or two underscores followed by an upper-case is reserved for the compiler. That's not always followed by people writing code, but that's what the C standard says [and thus the C++ standard, as they share these].
I think MS often uses _ in the beginning of a name to indicate that it's a private member variable (only visible inside the class).
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Some people use it to indicate a private member. There are some stringent rules on the use of the leading underscore in both C and C++, and they are not exactly the same in both languages. In theory you are allowed to use an underscore prefix only if the following character is a lowercase letter. Double underscores are out, as is an underscore followed by an uppercase letter.
You might think that you should be able to use any name you please if it's not at global scope, but this ignores the issue of macros which expand regardless of scope. The safest thing is to avoid the use of leading underscores entirely. You can still use underscores to mark private members, just place them at the END of the symbol instead of the beginning.
Code://try //{ if (a) do { f( b); } while(1); else do { f(!b); } while(1); //}
Thanks for your help again
The compiler and its standard library are allowed to:
1) Define extension keywords and macros (i.e. scope-agnostic things) with any name that starts with a double underscore or an underscore and a capital letter.
2) Use any name that starts with an underscore and a lowercase letter for variable or type names (i.e. scoped things).
Therefore, in order not to interfere with the compiler, your program must not:
1) use the first kind of reserved name (__foo and _Foo) in any way.
2) define macros or global variables/types with the second kind of reserved name (_foo).
Not that people care all that much. Here are some of the more blatant violations:
1) Microsoft loves extension keywords of the second reserved form, e.g. _asm.
2) I don't even want to start guessing how many projects use a single underscore prefix for their static globals.
3) X.org's code is littered with function and variable names like _Xsomething.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
Just so I am not making a mistake, the following would be valid?
I only as due to the no capital after the underscore warning, but im guessing the above isCode:#ifndef HEADER_H #define HEADER_H // blah code #endif
ok due to the underscore being between the header file name and the H
Double Helix STL
>> Just so I am not making a mistake, the following would be valid?
Yes. The underscore followed by capital letter rule is for the beginning of the symbol.