I'm working with a legacy C code which I need to document in UML. There's no immediate requirement to use those UML diagrams for synthesis, but there is a desire to go in that direction in the future.
Now, the code is riddled with features which can be enabled or disabled at compile time:
#if(FEATURE_X == ON)
deal_with_x();
#endif
Since there's no way to distinguish between compile-time and run-time conditions in UML (is there?), I end up using the same decision block for both, which means my diagrams really represent the following code:
if(FEATURE_X == ON) {
deal_with_x();
}
While I expect the compiler to eliminate the call when feature X is disabled, this is not quite the same code for at least two reasons:
deal_with_x()
has to be defined even if feature X is disabled- static code analysis will complain about dead code
What is the right way to deal with the situation? Is there a UML feature I'm not aware of that could help? Or should I create separate activity diagrams for different configurations (quite a work)? Or should I rely on the compiler to eliminate unnecessary calls and avoid using precompiler directives altogether?
While my question is about C code and precompiler directives, I can see the same problem can arise with C++ templates, especially if static if
gets introduced in the language.