I have two functions:
void prepare() and void finish() that will be called sequentially like:
prepare();
<do something>;
finish();
...
prepare();
<do something>;
finish();
I want to make a simple assertion to simply test that they are in fact being called this way and that they aren't being called concurrently or out-of-order in the application.
This application is a single-threaded application. This is a simple development/testing sanity check to make sure that these functions are being called in-order and that for whatever reason, they aren't being called concurrently. Furthermore, these assertions/sanity checks should be omitted from production code as performance is crucial!
would a simple assert() like this work best?
int test = 0;
void prepare() {
assert(++test == 1);
.
.
.
}
void finish() {
assert(--test == 0);
.
.
.
}
You might want to change
int test = 0;
to
#ifndef NDEBUG
int test = 0;
#endif
to satisfy your requirement that "any code relating to this test should be omitted from production".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With