Imagine a project with development stretched over more than 10 years. Some parts are in C, some of them are in C ++, and all the code uses global functions and global variables. The architecture was designed individually with one thread and constantly grew in this way. But now we are considering the use of multi-core architectures.
Now, one idea being analyzed is to reorganize part of the code into a library in order to create several instances so that they can work in separate threads and not interfere with each other.
The suggestion that is gaining the greatest value at this point is to wrap all library files in namespaces using macros, for example:
namespace VARIANT {
}
Then define VARIANTin the header or at the project level. This will allow you to have different contexts in different namespaces. And the selling point is that this approach requires minimal code changes and has a low risk of introducing any kind of regression.
But if at some point we need to make the behavior Variant1different from Variant2, the situation will become complicated, since there is no way to compare the value of the macro with the string in the macro of the preprocessor.
Is there a more elegant way to achieve this?
source
share