- summary changed from Check behavior when linking lib with contract disabled to check behavior when linking lib with contract disabled
I wanted to ask you about the behavior of Contract++ in the following scenario. I was trying to determine what happens if I link a program compiled with all contract checks disabled against the library compiled with all checks enabled. The code I tried is something like below:
file include.h:
CONTRACT_FUNCTION(
int (diff) ( (int) i, (int) j )
precondition(lessEqual(i, j))
);
file main.cpp:
int main()
{
auto i = diff(7, 5);
}
file second.cpp:
int CONTRACT_FREE_BODY(diff) (int i, int j)
{
return j - i;
}
I found that when I call my function diff() inside main(), the precondition is not checked -- expression not even evaluated -- even though it is compiled with precondition checks enabled. This is a very nice behavior, and a significant improvement over using asserts, because I do not have to recompile the library, when I want to disable the checks. I am just surprised that I didn't find it in the documentation.
Is this an intended feature? N1962 Describes a possible implementation of concept checks that adds no run-time overhead when contract disabled, not requiring at the same time the recompilation of the library. Is it also the case for your library? I know the preconditions are not evaluated in such "mixed configuration" but I cannot determine if some overhead connected to the function call is present.
If this is intended behavior, this feature is remarkable and deserves a honored place in the documentation. The docs do mention disabling the checks, but do not explicitly describe the "mixed mode". I thought that the library worked like normal assert's (If you change the setting you have to recompile the library). Or did I miss it in the docs?
Log in to post a comment.