the usage of "_"?

Started by
6 comments, last by GameDweeb 21 years, 2 months ago
Okay, I''m trying to read through the articles on writting a scripting language... I''m seeing "_" being used in front of variable names, just wondering what it does so I can understand the code better... Thanks for the help!
Advertisement
It''s sometimes used a prefix to signify member variables. Just a way know quickly being able to tell if it''s a member or something else.

I think it''s a terrible prefix, because _ is actually reserved for use by the compiler (for example when injecting code and stuff). Actually, it''s __ (double underscore) or _ followed by an uppercase letter (i.e. the regexp "_[_A-Z][0-9_a-zA-Z]") so it''s not that bad if all your identifiers are _ followed by a lower-case letter. Still, I just think it''s not a good idea...

If I had my way, I''d have all of you shot!

codeka.com - Just click it.
quote:Original post by Dean Harding
Still, I just think it's not a good idea...


It isn't a good idea, at all(In C/C++ at least). The compiler may have hidden definitions for various functions, variables, constants and macros, and they all begin with at least one underscore to separate them from whatever the user is doing. So if the user starts putting underscores before his own definitions, sooner or later you'll get a really obscure bug that nobody seems to be able to figure out, because you just tromped on something the compiler needed.

So just don't do it.

[edited by - MadKeithV on January 31, 2003 3:24:12 AM]
It's only funny 'till someone gets hurt.And then it's just hilarious.Unless it's you.
Hey thanks for the reply, helps a lot! Hehe, the explanation helped, but now I realize where I was getting confused and why I asked the question in the first place... My conclusion, I should stop trying to learn code concepts when I''m half awake! :-)
quote:Original post by Dean Harding
so it''s not that bad if all your identifiers are _ followed by a lower-case letter.


__ anywhere in the identifier, or _ + uppercase at the beginning are reserved for any use (they may even be keywords, e.g. __declspec)

_ + lowercase are reserved as names at global scope. It''s OK as local variables, class members or within namespaces.

It''s still way too close for my comfort though.

There are a number of other names reserved by the C (and thus C++) library. See here for further details.


[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
It just plain looks bad

Edit: Fruny your link on How To Ask Smart Questions is bad, needs to be corrected

OMG. It's him again. Call the SHRINK!!!
rambo_bones@hotmail.com
WebSite: http://www.illicitdev.net/~rambobones
GlRott Page: http://www.glrott.tk

[edited by - RamboBones on January 31, 2003 3:48:28 AM]
quote:Original post by RamboBones
Edit: Fruny your link on How To Ask Smart Questions is bad, needs to be corrected


Better ?


[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
quote:Original post by Fruny
__ anywhere in the identifier, or _ + uppercase at the beginning are reserved for any use (they may even be keywords, e.g. __declspec)

_ + lowercase are reserved as names at global scope. It''s OK as local variables, class members or within namespaces.

"C++ is like an Old Testament God, with lots of rules and no mercy"
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]

This topic is closed to new replies.

Advertisement