Archived

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

wah_on_2

#define V.S const

Recommended Posts

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