Jump to content
  • Advertisement
Sign in to follow this  
asdqwe

static question

This topic is 3930 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've got a game code (for Win32) from a book. The code compiles fine but something's off: the WinMain function declares a static variable! Like this: int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { static int iTickTrigger = 0; .................. } Any idea why he put "static" there? Thanks

Share this post


Link to post
Share on other sites
Advertisement
Erm.... no, not really. I could think of a couple ways this would be needed, but both of then are bad ideas anyway. I'm guessing that this variable was global and he forgot to remove static from it.

I'd also like to say: Please don't use Hungarian notation like he does.

Share this post


Link to post
Share on other sites
Why not Hungarian Notation? What should he be using then as a standard naming convention? I assume you dont simply expect people to make up their own naming conventions...

Share this post


Link to post
Share on other sites
Quote:
Original post by HumanoidTyphoon
Why not Hungarian Notation? What should he be using then as a standard naming convention? I assume you dont simply expect people to make up their own naming conventions...


There's an interesting approach which consists in naming the object after its semantic content, not its type. For instance, iTickTrigger tells you that it's an integer that somehow triggers a tick, or is triggered by a tick, or something else—the meaning of the variable is not really clear from its name. A better name, such as msUntilNextTick tells you that you're counting the milliseconds until the next tick happens—how the milliseconds are counted (integer? floating-point? something else?) is not as relevant as the fact that these milliseconds represent a delay before an event.

Share this post


Link to post
Share on other sites
Should you find yourself in a situation where you want to know the type of the variable you can often just hover over the variable in some (several?) IDEs such as in MS Visual Studio which will bring up a box detailing the type. You can also right click on the variable and click on the "go to declaration" option to be taken directly to the correct line of code.

As such, you know longer really need embed type information into a variable, except perhaps some rare situation.

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!