Jump to content
  • Advertisement
Sign in to follow this  
leoptimus

const in function parameters

This topic is 4866 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
Guest Anonymous Poster
AFAIK, const vars are only checked at compile time, so they won't affect performance... they're there to stop you from accidentally modifying their values...

Share this post


Link to post
Share on other sites
They CAN help performance in certain situations, and with a good optimizing compiler. As you know all it really does is signal to the compiler "this variable isn't going to change". Depending on the context in which it is used, most compilers can take advantage of that fact and generate faster, more memory friendly code.

Share this post


Link to post
Share on other sites
Here are two good Guru of the Week articles on const
Const Correctness
Constant Optimization

I've found const especially useful when passing a reference to a function. It's essentially a promise that you will not change the value of the variable, and will help protect you from yourself (accidentally changing the value of a variable when you don't want to).

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!