J
jacek.dziedzic
Hi!
I am for defensive programming and am working on a code stuffed with
quite a lot of assert-like statements, like
Asserts(pos==pos,"Position #"+to_string(i)+" is NaN");
where Asserts is
#define Asserts(expr,s) \
if(!(expr))
Framework::Asserts_Fail(__STRING(expr),__FILE__,__LINE__,__PRETTY_FUNCTION__,s)
and Asserts_Fail() displays a bunch of info and terminates the
program.
My question: a typical assert falls through 99.999% of the time as
if(!(expr)) is false. Am I guaranteed though, that the std::string
"Position #number is NaN" would not be constructed in vain _every
time_ this assert is checked? My understanding is that since this is a
macro, not a function call, then it is only constructed when the
assert actually clicks and Asserts_Fail() is called. If Asserts() was
made to be a function call instead of a macro, then I might not be as
lucky.
Can anyone confirm or contradict this?
TIA,
- J.
I am for defensive programming and am working on a code stuffed with
quite a lot of assert-like statements, like
Asserts(pos==pos,"Position #"+to_string(i)+" is NaN");
where Asserts is
#define Asserts(expr,s) \
if(!(expr))
Framework::Asserts_Fail(__STRING(expr),__FILE__,__LINE__,__PRETTY_FUNCTION__,s)
and Asserts_Fail() displays a bunch of info and terminates the
program.
My question: a typical assert falls through 99.999% of the time as
if(!(expr)) is false. Am I guaranteed though, that the std::string
"Position #number is NaN" would not be constructed in vain _every
time_ this assert is checked? My understanding is that since this is a
macro, not a function call, then it is only constructed when the
assert actually clicks and Asserts_Fail() is called. If Asserts() was
made to be a function call instead of a macro, then I might not be as
lucky.
Can anyone confirm or contradict this?
TIA,
- J.