Re: Using template in safety-critical system (flight critical system)
Lionel B wrote:
aeromarine wrote:
I want to know whether I can use template in safety-critical
system or not.
Why not, if they're useful to the task at hand?
you can probably assume that "modern" compilers implement
templates as well as they do any other basic language
construct
Ideally.
Templates with template<> look like useful and any code is better to
write with templates, than without.
If you have an interest with OOD/OOP, you can see, that with
template<> you can declare for C++ pure-like obj-oriented, abstract
template (implementation independed template).
Abstract template is a way to write reusable components of software.
Any abstract template implies polymorphic behaviour for all things
called as template parameters.
You can select concrete implementation of an abstract template as
compile time template (abstract template will be implemeted as
multiple copies of code), or as run time template (abstract template
will be implemeted as singe copy of code and multimple function
calls). In most cases runtime template implies at least one virtual
function call.
You can also refuse from polymorphic behaviour of abstract template
and turn your template into plain code. In the case, you will not see
any differences between templated or non-templated code, but correctly
designed templated components of code can be reused in future.
namespace Ncomponents
{
template<typename VeryLongClassName, typename EvenMoreLongClassName >
class A;
template<
typename VeryLongClassName,
typename EvenMoreLongClassName,
typename MoreThanEvenMoreLongClassName
>
class B;
B< TerTerTer, int, B< TerTerTer, int > > b;
}
namespace Nnon_polymorphic
{
typedef Ncomponents::A< TerTerTer, int > A;
typedef Ncomponents::B< TerTerTer, int, A > B;
B b;
}
Really.
1. template's syntax looks worse than C/C++ traditional one
template<typename VeryLongClassName, typename EvenMoreLongClassName >
class B;
template<typename VeryLongClassName, typename EvenMoreLongClassName,
typename MoreThanEvenMoreLongClassName>
class A;
A<TerTerTer, int, B<TerTerTer, int> >
is not better than
class B;
class A;
A;
The long declarations make understanding the code more difficult, that
leads to errors due to human confusions.
2. abstract templates are not completely supported by C++ (at least
now): there are no enough "sintaxic sugar" and C++ compiler supports
only trivial operations with abstract templates at compile time.
"Concepts", for example, will try to add some stuffs for the support,
but we need real compiler with concepts to test the stuffs.
3. abstract templates are inclined to remove some detectable during
compile-time errors to end-user rather to desiner of the component.
4. some real compilers has limitations to work with templated source -
they are hard to trace, hard to see output, hard to link, etc.
So, you can select :)
By the way, C++ has no enough stuffs to control implementation of
abstract code.
Ideally, when we declare function, we do absract code; means that from
implementation point of veiw, even C-style function is abstract
function; means once declared, function must be able to be implemented
in different manner, as template<> do.
For example:
//my_function declaration
//default implementation
extern "C++, inline, register, nothrow"
void
my_function(int, int);
//usage of my_function
//some times per execution
//compiler makes outline copy of my_function
my_function::(extern "outline, stdcall")(0,0);
for(int i=1000000; i; --i)
{
//by default
my_function(i,0);
//force fast copy for unknown defaults of my_function
my_function::(extern "inline, register")(0,i);
}
Maksim A. Polyanin
http://grizlyk1.narod.ru/cpp_new