-
JETeranLikes 0Problem Description
Greetings.
We are creating a file called Definitions.h where we wrote:
#define DISPLAY_TIME_SPLASH_SCENE 2 #define TRANSITION_TIME 0.5
Then we use both defines in the code. But my question is, why should we use #define instead of declaring a global constant with the same valor?
Thanks once again!
-
Sonar Systems adminLikes 0
When you say a global constant do you mean a global constant variable?
-
JETeranLikes 0
Hello there.
Yes indeed. For what I know about programming (still learning!) is that we can declare a global constant variable to use it in many parts of the code. What is the difference between this and declaring it as a #define ?
-
Sonar Systems adminLikes 0
Take a look at this conversation, this should help you http://stackoverflow.com/questions/1674032/static-const-vs-define-vs-enum
-
JETeranLikes 0
It did, thank you.
Reading further, I found out that using #define is the less recommended by developers, do you also agree? As everything, has is Pros and Cons. Anyways, I will continue working as you are teaching me!
-
Sonar Systems adminLikes 0
I personally prefer #defines, but honestly find what works for you and the situation you are programming for.
Loads of stuff are considered bad coding practise but many big companies will practise and even encourage them because it makes life easier.
-
JETeranLikes 0
Thanks so much for sharing your preferences.
I will continue using them as you do in the tutorials. Thanks once again!
-
Sonar Systems adminLikes 0
Your very welcome, do no hesitate to ask anymore questions.
Login to reply