• Advertisement

Archived

This topic is now archived and is closed to further replies.

the usage of "_"?

This topic is 5497 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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! :-)

Share this post


Link to post
Share on other sites
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 ]

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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 ]

Share this post


Link to post
Share on other sites
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"

Share this post


Link to post
Share on other sites

  • Advertisement