Rob
2003-10-05 09:08:31 UTC
I'm interested in gathering peoples views on the use of C++ for
safety critical systems. I have seen some evidence of debates
in safety communities but I have seen little evidence of thought
on this specific area since C++ was standardised.
To start the discussion, some views on the topic follow.
The major challenge of developing safety critical software is
understanding and clearly articulating the requirements. Once
that is done, the impact of selected programming language becomes
significant. Higher levels of safety integrity, such as SIL4
(Safety Integrity Level 4) or D0178B (Level A) is that system testing
can not provide adequate levels of assurance, and this normally
implies a need to demonstrate, to an independent third party who
has the authority to initiate system design changes, that the design
is correct. In practice, this demonstration is usually required to
be sufficient to demonstrate that the compiled code actually
represents the design correctly and unambiguously. The basic
assumption of these safety levels is that *any* error in a design
or in coding may cause loss of life.
While it is reasonable to assume that any language is used
intelligently, it is equally unreasonable to assume every programmer
is an expert. In a large language like C++ this becomes a concern for
safety critical systems, because there is a distinct possibility that
two programmers may examine a body of code, and draw different
conclusions about what it does. Regular questions in this newsgroup
on the interpretation of parts of the language are a symptom of this.
In fairness, C++ is not the only language like this; even Ada --- a
language intended to be used without subsetting for developing safety
critical systems --- has subsets defined to remove certain language
features before it can be safely used for SIL4 software development
(eg the Spark subset). But areas on concern include:
a) areas where the standard explicitly states there is "undefined
behaviour", or "implementation defined behaviour". In other words,
two implementations may generate different results from the same
source code, and both may be correct! Some of these implementation
freedoms may influence the behaviour of correct programs, resulting
in unpredictable flows of execution. In principle, this could be
addressed by examining machine code output by a compiler, but that is
possibly too time consuming to be effective when verifying flows
of execution in large bodies of code.
b) it is often difficult to demonstrate that there is no resource
leak, or to bound resource usage statically. There are several
design techniques (eg RAII) to help prevent resource leaks, but how
can an independent reviewer determine if these techniques are
always being applied? With the use of the STL [as an example] how
is it possible to ensure that resource usage does not grow in
unexpected ways?
c) there are some language features that, even though precisely
defined, may fairly be described as difficult to understand or easy
to abuse in ways that may deceive an independent reviewer. Multiple
inheritence and some uses of templates arguably fall into this
category: language features that give significant benefits if used
well, but are also open to abuse (whether deliberate or accidentally).
Having raised some concerns with C++, there are some points in its
favour;
a) There is a large infrastructure based on research, experience,
and excellent publications about better ways to use C++.
b) Several tools are available for C or C++ well before they become
available for other languages. Several tool manufacturers don't even
bother with other languages. Many of these tools make it easier to
spot mistakes and to test code. Other tools make it easier to write
code with fewer errors in the first place --- and they do it
automatically. Some system engineering tools help with requirements
capture, and help ensure a direct connection between the design and
the code that implements it.
c) It is relatively easy to find a software engineer who is familiar
with C++. For example, it could be argued that it is more difficult
to find a skilled Ada person than it is to find a skilled C++ person,
simply because there are more commercial applications of C++ than Ada,
so people are more likely to develop skills and then keep their hand
in with C++.
Whether or not these "big picture" arguments adequately address the
weaknesses of C++ (eg at the language level) for safety critical
applications is obviously a point for discussion.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
safety critical systems. I have seen some evidence of debates
in safety communities but I have seen little evidence of thought
on this specific area since C++ was standardised.
To start the discussion, some views on the topic follow.
The major challenge of developing safety critical software is
understanding and clearly articulating the requirements. Once
that is done, the impact of selected programming language becomes
significant. Higher levels of safety integrity, such as SIL4
(Safety Integrity Level 4) or D0178B (Level A) is that system testing
can not provide adequate levels of assurance, and this normally
implies a need to demonstrate, to an independent third party who
has the authority to initiate system design changes, that the design
is correct. In practice, this demonstration is usually required to
be sufficient to demonstrate that the compiled code actually
represents the design correctly and unambiguously. The basic
assumption of these safety levels is that *any* error in a design
or in coding may cause loss of life.
While it is reasonable to assume that any language is used
intelligently, it is equally unreasonable to assume every programmer
is an expert. In a large language like C++ this becomes a concern for
safety critical systems, because there is a distinct possibility that
two programmers may examine a body of code, and draw different
conclusions about what it does. Regular questions in this newsgroup
on the interpretation of parts of the language are a symptom of this.
In fairness, C++ is not the only language like this; even Ada --- a
language intended to be used without subsetting for developing safety
critical systems --- has subsets defined to remove certain language
features before it can be safely used for SIL4 software development
(eg the Spark subset). But areas on concern include:
a) areas where the standard explicitly states there is "undefined
behaviour", or "implementation defined behaviour". In other words,
two implementations may generate different results from the same
source code, and both may be correct! Some of these implementation
freedoms may influence the behaviour of correct programs, resulting
in unpredictable flows of execution. In principle, this could be
addressed by examining machine code output by a compiler, but that is
possibly too time consuming to be effective when verifying flows
of execution in large bodies of code.
b) it is often difficult to demonstrate that there is no resource
leak, or to bound resource usage statically. There are several
design techniques (eg RAII) to help prevent resource leaks, but how
can an independent reviewer determine if these techniques are
always being applied? With the use of the STL [as an example] how
is it possible to ensure that resource usage does not grow in
unexpected ways?
c) there are some language features that, even though precisely
defined, may fairly be described as difficult to understand or easy
to abuse in ways that may deceive an independent reviewer. Multiple
inheritence and some uses of templates arguably fall into this
category: language features that give significant benefits if used
well, but are also open to abuse (whether deliberate or accidentally).
Having raised some concerns with C++, there are some points in its
favour;
a) There is a large infrastructure based on research, experience,
and excellent publications about better ways to use C++.
b) Several tools are available for C or C++ well before they become
available for other languages. Several tool manufacturers don't even
bother with other languages. Many of these tools make it easier to
spot mistakes and to test code. Other tools make it easier to write
code with fewer errors in the first place --- and they do it
automatically. Some system engineering tools help with requirements
capture, and help ensure a direct connection between the design and
the code that implements it.
c) It is relatively easy to find a software engineer who is familiar
with C++. For example, it could be argued that it is more difficult
to find a skilled Ada person than it is to find a skilled C++ person,
simply because there are more commercial applications of C++ than Ada,
so people are more likely to develop skills and then keep their hand
in with C++.
Whether or not these "big picture" arguments adequately address the
weaknesses of C++ (eg at the language level) for safety critical
applications is obviously a point for discussion.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]