I have few questions about pre-processor macros. Here is an example of 2 different code pieces to talk about;
tmp.h
#define DEFAULT_STRING "default_value"
tmp.cpp
void tmpFunc(std::string newValue){
m_stringValue = newValue;
if(newValue.isEmpty())
newValue = DEFAULT_STRING;
}
And the second version
tmp.h
const std::string m_defaultValue = "default_value"
tmp.cpp
void tmpFunc(std::string newValue){
m_stringValue = newValue;
if(newValue.isEmpty())
newValue = m_defaultValue;
}
So my questions are;
- Does the first version increase the binary size (comparing the first second)?
- Does the second version consume more memory (comparing the first one)?
- What are the performance impacts of both implementations? Which should run faster and why?
- Which is preferable/beneficial in which condition?
- Is there any better way for implementation of setting the default value?
Thanks.