Sign in to follow this  

static question

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

This topic is 3714 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this