Jump to content
  • Advertisement
Sign in to follow this  
XenoPhyre

C++ Variable Names?

This topic is 3699 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

Advertisement
No.

Once the source code is compiled variable names are lost. Variables having names is just a high level way for you to be able to associate a piece of memory with a certain purpose. This is fundamental in high-level languages. High level languages are compiled down into machine code.

It may appear otherwise when you are debugging with Visual Studio and the like, but this is only because the IDE does a lot of work in the background to allow you to see what is going on in your code by looking at the variables by name, for example, the Watch Window.

Hope that helps,

Share this post


Link to post
Share on other sites
They aren't.

They're only used by the compiler to tell your variables apart. During compilation, they're simply translated into addresses, stack pointer offsets or registers.

In the compiled executable, variables don't exist. There's just code that says "load whatever is at address X into register Y. Add whatever is in register Y to whatever is in register Z. Store the result at this offset from the current top of the stack".

Names, or even the concept of variables just don't exist.

[Edited by - Spoonbender on June 28, 2008 8:00:53 PM]

Share this post


Link to post
Share on other sites
Ahhh. Both of you really made things a lot clearer for me. Thanks! Looks like I just learned something about my computers' innards :X

Share this post


Link to post
Share on other sites
Quote:
Original post by XenoPhyre
Ahhh. Both of you really made things a lot clearer for me. Thanks! Looks like I just learned something about my computers' innards :X


Heh. In fact, this is how source obfuscators work - they rename all of the variables and functions and what-not to unreadable names like _00111000O__O0011O:

void _10101011OO01O1100(___011O __0000O01){____OOO11O00._0001O_1110->O0001(__0000O01);}

Try figuring out what THAT does [lol].

The compiler and final binary doesn't care, if you you ask a human to read some piece of code with such variable names, uh. Yeah, no, it won't happen [grin].

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!