I thinked at two techniques for my #define :
Technique 1
SomeClass.h:
#define SOME_BUFFER_LENGTH 256
class SomeClass {
/* ... */
};
Technique 2
Config.h:
#define SOME_BUFFER_LENGTH 256
#define SOME_OTHER_THING_USED_ELSEWHERE 23
SomeClass.h:
#include "Config.h"
#ifndef SOME_BUFFER_LENGTH
#define SOME_BUFFER_LENGTH <Default Value>
#endif
class SomeClass {
/* ... */
};
What are pros and cons of these two methods, and objectively for a big project, which is the best ?
Edit:
Hi, I learnt two things from your comments and answers :
@gnasher729: If there might be reasons to change it to a different value, then it's bad if you have to hunt down such constants in many different source files, but better to have it in a configuration file with the express intent to configure things.
and
@Phil1970: Better to use C++ constants instead of the processor.
So I end with this behavior:
Config.h:
namespace Config {
const type constant = value;
const type anotherconstant = anothervalue;
}
SomeClass.h:
#include "Config.h"
/* ... */
void somefunc() {
usefulfunc(Config::constant, /* ... */);
}
I think it's perfectly suitable for an OpenSource project, I'm awaiting your point of views about this !