[SystemSafety] MC/DC handling of conditional operators
Derek M Jones
derek at knosof.co.uk
Wed Oct 30 13:10:30 CET 2024
All,
I have not seen an analysis of MC/DC that involves
conditional operators in if-statement conditions.
Why would anybody use conditional operators (also known as
a ternary operator) in this context you ask?
I thought the same until some recent analysis of
if-statement conditions.
As its name suggests, the conditional operator involves a
condition, and as such looks like it needs to be addressed
by MC/DC (I have added parenthesis to the following examples
to make things clear):
In: 1+(c!=0 ? x : y)
if c is not equal to zero, the result is 1+x,
otherwise the result is 1+y.
Now in C, C++ and other languages we can write:
if (1+(c!=0 ? x : y) == z)
foo=bar;
or we can write the longer equivalent code
if (c != 0)
{
if (1+x == z)
foo=bar;
}
else
{
if (1+y == z)
foo=bar;
}
All the analysis of MC/DC that I have seen only involves
logical AND and logical OR.
Is the behavior of conditional operator something that gets
ignored?
Is there an unwritten MC/DC rule that conditional operators
not be used in if-statement conditions?
Shouldn't the conditional operator be part of the MC/DC
analysis, i.e., required to be tested along both arms?
SQLite says they achieve 100% MC/DC
https://www.sqlite.org/testing.html#mcdc
The SQLite source contains instances of the conditional
operator if if-statement conditions
https://shape-of-code.com/2024/10/13/if-statement-conditions-some-basic-measurements/
Does anybody know how SQLite+MC/DC deals with the
conditional operator?
--
Derek M. Jones Evidence-based software engineering
blog:https://shape-of-code.com
More information about the systemsafety
mailing list