Jump to content
  • Advertisement

Archived

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

wah_on_2

#define V.S const

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

What is the different between #define with const? Which one is better?(e.g. which one will save more memory?, which one performance is better?) Thx a lot of.

Share this post


Link to post
Share on other sites
Advertisement
In C++, with a decent optimising compiler, const is better. Anything which makes your intentions clearer to the compiler increases the _potential_ for better optimisations.

#define is just a pre-processor macro, what appears in it gets substituted before compilation. The main reason to use #define is if you have a constant which is also used in a C or assembly language program.

--
Simon O''''Connor
Creative Asylum Ltd
www.creative-asylum.com

Share this post


Link to post
Share on other sites
oic. thx!

but what does it mean?

"The main reason to use #define is if you have a constant which is also used in a C or assembly language program."

Is it mean if i will not use C or assembly language, i can no need use #define?


Share this post


Link to post
Share on other sites
Guest Anonymous Poster
If your using C++ (like you said) I would recommend using "const" because it allows "type" safety, so the compiler can help you fix things and remove allot of the hassle.

"Define" is sometimes better in some situations for advanced program modification just because of the way it works. I''d say
more but I''m really strapped for time. (Sorry... ^_^)

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!