I am working on a project in C Visual Studio, and I have two sets of functions, let’s call them SET_1
and SET_2
.
I wonder if there is a way to ensure that a function from SET_1
calls only functions from SET_1
and not functions from SET_2
.
The simplest solution will be to split the project in 2, but I want to avoid any major refactoring. I probably can make some runtime checks but I want to avoid this too…
So, I am wondering if there is something like SAL annotations
that I can use to enforce this isolation at compile time?
Here is an example of what I want:
#define SET_1 ...
#define SET_2 ...
SET_1
void Fct1()
{
// ...
}
SET_1
void Fct2()
{
Fct1(); // Ok, both functions have SET_1 tag
}
SET_2
void Fct3()
{
Fct1(); // Compile error, Fct1 has a different tag
}
I don’t want to write some kind of code parser to manually enforce this rule.
I have multiple files and a file contains functions from both sets. The functions don’t have any common characteristic, I manually need to specify the set for each function.
The solution can be at compile time or at build time. I just want to make sure that a function from set1
will not be called from set2
I can modify the code and I know that the right solution will be to refactor the project, but I am curious if there is another solution.
For example, if the code was in C++, I could include all functions from set1 inside a namespace and those from set2 inside another namespace. But this will not work if we have a class with function members in different sets.