473,748 Members | 6,037 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Teaching new tricks to an old dog (C++ -->Ada)

I 'm following various posting in "comp.lang. ada, comp.lang.c++ ,
comp.realtime, comp.software-eng" groups regarding selection of a
programming language of C, C++ or Ada for safety critical real-time
applications. The majority of expert/people recommend Ada for safety
critical real-time applications. I've many years of experience in C/C++ (and
Delphi) but no Ada knowledge.

May I ask if it is too difficult to move from C/C++ to Ada?
What is the best way of learning Ada for a C/C++ programmer?

Jul 23 '05
822 29615
Ioannis Vranos wrote:

[ ... ]
unsigned char *a = reinterpret_cas t<char *>(&x);
unsigned char *a = reinterpret_cas t<unsigned char *>(&x);


Oops -- quite right. Fortunately, despite it's reputed lack of safety,
any properly-functioning C++ compiler would have caught my mistake had
it been in real code.

[ ... ]
Also since Ada is more ancient than C++ in terms of a final standard,
we can expect that some things are "more ancient", but it is still
an interesting language since it can do low level stuff.
I'm not sure "ancient" applies to either -- at least the last time I
noticed, the most recent Ada standard was approved in 1995, which is
marginally older than the C++ standard. I'm not really sure this means
a lot though -- most of the basic ideas of C++ were fixed by then in
any case. Certainly there were changes in the text of the rules after
that point, but most of these were to get the rules to require what had
already been decided upon, not things that were intended to change the
language.
I am not sure it is "safer" than C++ too, I am suspicious of "safe"
languages.


The first problem is to define what you mean by safety. Bjarne has been
fairly explicit that most safety features in C++ are intended to
prevent accidents, not intentional subversion. It's always seemed to me
that Ada has had a rather muddled idea of the "threat model", so the
language features have never been entirely aligned to a single intent.
Some parts appear intended to prevent accidents, but are quite easy to
subvert when one wishes to do so. Other parts appear to have been
designed with the intent of preventing even intentional subversion, but
fail to do so, and simply render some things quite a bit uglier than
there seems to be good reason for.

In fairness, I should add that my personal experiece with Ada was
almost entirely with the 1983 version, so it's entirely possible that
at least some of these have been fixed -- OTOH, looking at the code
snippets posted to this thread, it looks like at least some of the
ugliness remains.

--
Later,
Jerry.

The universe is a figment of its own imagination.

Jul 23 '05 #141


Hans Malherbe wrote:
support efficient, real-time safe environments

Can you explain the "real-time" part?

Reading this thread, it seems to me Ada's focus is on safety rather
than efficiency.
These safety constraints also tend to limit expressiveness. Not that
safety is bad, just that it's not free.


Actually, a close reading of the thread should have made it clear that
the additional safety is indeed "free". Since the majority of Ada's
checks are compile time they do not impact on run-time efficiency.
Where Ada's goals can only be met by run-time checks these are no more
expensive than equivalent manually-inserted checks in any other language
(and are often less because Ada provides the compiler with more
information by which to judge when they can safely be optimised away).
They can, in any case be turned off if the user requires a different
performance/safety tradeoff.

It should also have been clear from the thread that Ada imposes no
limits on expressiveness.

Can you say what led you to the opposite conclusion?

Peter

Jul 23 '05 #142
In article <11************ **********@o13g 2000cwo.googleg roups.com>, "Hans Malherbe" <ha***********@ gmail.com> writes:
support efficient, real-time safe environments
Can you explain the "real-time" part?

Reading this thread, it seems to me Ada's focus is on safety rather
than efficiency.


Many of these checks have been described as being compile-time checks.
A goal of fast compiles should not dominate.
These safety constraints also tend to limit expressiveness. Not that
safety is bad, just that it's not free.


Nobody has come up with something that cannot be expressed in Ada (or
in C++ for that matter). Ada code is more verbose, on the grounds that
code is read more often than it is written (or at least it should be).
Jul 23 '05 #143
On Tue, 08 Mar 2005 15:27:35 +0200, Ioannis Vranos wrote:
Dr. Adrian Wrigley wrote:
C++ was designed to produce an object-orientated
extension to C.

An all too common misconception.

enlighten us please!


C++ is a multiparadigm language and supports 4 paradigms. Each paradigm
is supported *well* with optimal space and time efficiencies.

It does not enforce a specific paradigm, but allows the mixing of them
as the programmer thinks it fits better for a specific problem.


This is is well known.

I was asking for my misconception on what *C++ was designed for* to
be dispelled.
--
Adrian

Jul 23 '05 #144

Peter Amey <pe********@pra xis-cs.co.uk> writes:
manually-inserted checks in any other language (and are often less because
Ada provides the compiler with more information by which to judge when they
can safely be optimised away).


For example (if you ask):

type Table is array (1 .. 10) of Integer;

Data : Table;

for K in Data'Range loop
if Data (K) = 1 then
...
end if;
end loop;

There is no need to check K validity inside the loop as "Data (K)" is always
correct by definition (K in Data'Range). Just an example.

Pascal.

--

--|------------------------------------------------------
--| Pascal Obry Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--| http://www.obry.org
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595
Jul 23 '05 #145
Peter Amey wrote:


Hans Malherbe wrote:
support efficient, real-time safe environments
Can you explain the "real-time" part?

Reading this thread, it seems to me Ada's focus is on safety rather
than efficiency.
These safety constraints also tend to limit expressiveness. Not that
safety is bad, just that it's not free.


Actually, a close reading of the thread should have made it clear that
the additional safety is indeed "free".


Free? Well, lets look at one particular issue: pointers to arbitrary
locations. In C, its a common idiom to do the following:
foo(int * p)
{
int * z;
for( i ... ) {
... p[i]...;
}
z = p;
}

...
foo( &x[lo] );
...

Now, how can *any* language check to see that p[i] is within bounds?

The usual solution is to pass p as a "handle"; basically, pass two
pointers, one of which is the pointer to the descriptor of the
containing "object" (which could be x or something containing x), or
alternatively, pass a pointer to a record that contains x and p. z, in
particular, will have to be a 2 element record, again containing x and p.

A dereference via z will have to become a double dereference; first load
p from z then load from p.

Not quite free.
Since the majority of Ada's
checks are compile time they do not impact on run-time efficiency.
Where Ada's goals can only be met by run-time checks these are no more
expensive than equivalent manually-inserted checks in any other language
(and are often less because Ada provides the compiler with more
information by which to judge when they can safely be optimised away).
Bullsh*t. In several ways, of which two are:
- Usually the checks will be added every place they are needed, and then
the usual optimizations will be used to eliminate them. In other words,
if one adds the checks manually, the compiler should eliminate them
identically.
- Going back to the problem of finding the countaining object for some
pointer. If one is adding the code by hand, one can use several options
NOT available to a compiler.
* what if z always points to objects inside x (but the compiler can't
figure it out).
* what if the containing object for p is always allocated on some 2^n
byte boundary?

There are other interesting things one can do for safety that are less
memory/CPU intensive than what a language can give you automatically.

Have a look at http://users.bestweb.net/~ctips for some of the ideas.
They can, in any case be turned off if the user requires a different
performance/safety tradeoff.
Are you sure? Do I have to recompile the whole program in that case? Or
reannotate the whole program? The above "handles" case is particularily
pernicious. If a sub-program is compiled to not expect handles [because
we just turned off that protection feature], but its caller is still
passing handles, well - interesting things will ensue.
It should also have been clear from the thread that Ada imposes no
limits on expressiveness.
How easy is it to build an arena allocator in Ada?

Given a processor with load-word-locked and store-word-conditional, how
would I build an atomic increment function?
Can you say what led you to the opposite conclusion?

Peter

Jul 23 '05 #146

CTips <ct***@bestweb. net> writes:
Free? Well, lets look at one particular issue: pointers to arbitrary
locations. In C, its a common idiom to do the following:
foo(int * p)
{
int * z;
for( i ... ) {
... p[i]...;
}
z = p;
}

...
foo( &x[lo] );
...

Now, how can *any* language check to see that p[i] is within bounds?
Good you asked! Let's code this example in Ada (using Ada and
not C/C++ style, in Ada for the above example we do not need a pointer):

type T is array (Positive range <>) of Integer;

procedure Foo (P : in out T) is
Z : Positive;
begin
for I in P'Range loop
... P(i)...;
-- Here P(i) is always within the bounds, no check needed.
end loop;
Z := P'First;
end Foo;

...

Foo (X (Lo .. X'Last));
Bullsh*t. In several ways, of which two are:


Given your assumption about maybe you just don't know Ada.

Pascal.

--

--|------------------------------------------------------
--| Pascal Obry Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--| http://www.obry.org
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595
Jul 23 '05 #147
John Hudak writes:
What??????????? ??????????????? ??????????????? ???????? Assembly
language? powerful? If you decide to write a X GUI interface in
assembly, I'll check in on you in 20 years to see how your
doing.... Higher level languages handle broader abstract concepts
better than low level languages. Assembly is great if you are
optimizing device drivers or banging bits at the hardware register
level...not good at implementing scientific algorithms, GUIs,
databases, etc. There are thousands of reasearch papers that extol
the problems of assembly language approach to things, and yes, there
are places and reasons to use it, but classifying it as a 'higher
level language' and something more powerful is incorrect....
-John


I think the problem is to define what everyone means by "powerful".

If by "powerful" I mean "I can do exactly anything I want", or "I can
get the most out of my hardware", then assembly is the most powerful
language.

If OTOH "powerful" means "I can program quickly", then assembly is not
powerful, but e.g. SQL or Delphi are.

--
Ludovic Brenta.
Jul 23 '05 #148
"Jerry Coffin" writes:
In fairness, I should add that my personal experiece with Ada was
almost entirely with the 1983 version, so it's entirely possible that
at least some of these have been fixed -- OTOH, looking at the code
snippets posted to this thread, it looks like at least some of the
ugliness remains.


The "use type" feature of Ada 95 alone makes Ada 95 *much* more
pleasant to program with. Check it out. And yes, we allow it in our
coding standards :)

--
Ludovic Brenta.

Jul 23 '05 #149
"Jerry Coffin" writes:
Ludovic Brenta wrote:
I could make the code less verbose by using use clauses, similar to
"using namespace std" which you seem fond of. In avionics, our
coding standards forbid that because we want everything to be
explicit.


A poor idea. Just for example, consider writing a generic sorting
function. It needs to swap items that it's sorting. In well-written
C++, this will often be done with a using clause. Specifically, if
the type of items has provided its own specialized version of swap,
then my sorting functino should use that, but otherwise it should
use std::swap to swap them.

I try to specify whatever_type:: swap(x,y), then compilation will
fail if the type has not provided a swap function. Conversely, if I
specify std::swap(x,y), then the specialized swap function won't be
used for those types that provide one.


Ada requires explicit instanciation of all templates, so there is no
"default". We do not have problems using fully-qualified names.

Ada 95's object-oriented features do not suffer from this either.

package P is
type Base is tagged null record;

procedure Method (B : in Base);
end P;
with P;
package Q is
type Derived is new P.Base with private;

procedure Method (B : in Derived); -- overloads P.Method
private
-- omitted
end Q;
with P;
procedure Dynamic_Dispatc h (B : in Base'Class) is
begin
P.Method (B); -- [1]
end Dynamic_Dispatc h;

The procedure Dynamic_Dispatc h does not see package Q, yet it can call
Q.Derived if it receives an instance of Q.Derived as its parameter.
This, *even* without a use clause.

--
Ludovic Brenta.
Jul 23 '05 #150

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
2356
by: Mediocre Person | last post by:
Well, after years of teaching grade 12 students c++, I've decided to make a switch to Python. Why? * interactive mode for learning * less fussing with edit - compile - link - run - debug - edit - compile - link - run -..... * lots of modules * I was getting tired of teaching c++! Bored teacher = bad instruction.
14
1827
by: Gabriel Zachmann | last post by:
This post is not strictly Python-specific, still I would like to learn other university teachers' opinion. Currently, I'm teaching "introduction to OO programming" at the undergrad level. My syllabus this semester consists of a bit of Python (as an example of a scripting language) and C++ (as an example of a compiled language). With C++, I go all the way up to meta-programming. My question now is: do you think I should switch over to...
3
1536
by: andy_irl | last post by:
Hi there I have been asked to teach HTML to a group in our local village community. It is nothing too serious, just a community development grant aided scheme. It will be a 10 week course of two hours per week and will mainly consist of mature students. I may or may not include GUI's depending if I can fit it all in to the time allocated. I was wondering if anyone could point me to any useful teaching resources for HTML on the web ie...
12
1998
by: Pierre Senellart | last post by:
I am going to teach a basic Web design course (fundamentals of HTML/CSS, plus some basic client-side (JavaScript) and server-side (PHP, perhaps XSLT) scripting). Most of the students do not have any previous knowledge of all of this. I am strongly considering teaching XHTML 1.0 Strict instead of HTML 4.01 strict, for the following reasons: - XML syntax is far more simple to teach than HTML/SGML, simply because there are not as many...
16
4376
by: msnews.microsoft.com | last post by:
I am teaching C# to my 11 year old child. One challenge is that all the C# books I own and that I have seen in bookstores are full of language that is not easily comprehended by a student at that age. Can anyone recommend books (or perhaps websites) tuned for younger audiences? BTW, its amazing how fast a student can absorb this kind of information at that age. Lucky them! Thanks, Bruce
24
2858
by: Richard Aubin | last post by:
I'm really new to vb.net programming and programming in general. I would like to teach myself on how to program effectively and I have the financial and time resources to do so. Can I anyone recommend and point me in the right direction where I should start? -- Richard Aubin
0
1714
by: e.expelliarmus | last post by:
check this out buddies. kool website for: * hacking and anti hacking tricks * anti hackng tricks. * registry tweaks * orkut tricks * small virus * computer tricks and loads of different tricks... www.realm-of-tricks.blogspot.com www.registrydecoded.blogspot.com
1
3893
by: JosAH | last post by:
Greetings, Introduction This week's tip describes a few old tricks that are almost forgotten by most people around here. Sometimes there's no need for these tricks anymore because processors nowadays are so fast and memory comes in abundance. But still, if we implement an algorithm that is better, or more efficient, than another one, those faster processors run the first algorithm faster than the other one. If an algorithm takes less...
0
8830
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9544
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9324
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8243
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6074
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3313
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2783
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.