Skip to main content
gamedev.net
🔒 Locked

#define V.S const

Started by wah_on_2 3 replies 200+ views
Original Post
wah_on_2
wah_on_2
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.
S1CA
S1CA
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
Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site
wah_on_2
wah_on_2
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?


Countach
Countach
Also do a lookup on ''enum''. Perhaps you''ll like that even better.



Reach out and torch someone.
-------homepage - email

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.