473,796 Members | 2,541 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 29831
REH

"Ioannis Vranos" <iv*@remove.thi s.grad.com> wrote in message
news:1110607809 .837000@athnrd0 2...
I am pretty sure one can write a library that can enable just that.
Now that I am thinking of it, there are some, and let's begin from Boost:
http://www.boost.org/libs/integer/integer.htm
#include <boost/integer.hpp>
int main()
{
using namespace boost;

int_t<24>::leas t my_var;
}

with "least" being the smallest built-in type that supports the given bit
count.

You see, that's easy. :-) Just "plug in" Boost.

Yes, I'd used Boost. It's an amazing library, but the above is not
equivalent to what I wrote. The major different, and the feature I'd mainly
like to see in C++ in that the definition of Byte above is a unique type.
It can participate in overload resolution. Different typedefs using
int_t<24> are not distinct. I know this can be achieved with an extra
template parameter, enums, or classes, but I don't want to go to that kind
of effort just to tell the compiler to treat it as a unique type. Another
difference, in C++ you cannot create an array of int_t<3> and have all the
element be exactly 3 bits. Using 'size and 'component_size (or even pragma
pack), in Ada you can. I can also specify a range other than zero to max.
You may not care (as your other post suggests), but for fault tolerance, I
do.

Don't get me wrong. I'm not one of the C++ bashers (I think
language-bashing is nonsense). C++ is my favorite language. But Ada has
some really nice features I'd like to see in it. I don't care about the
forced range checking. I don't think that "fits" C++. I would however,
like to be able to easily define unique types of primatives. Being able to
portable and explicitly define its size in bits (so that arrays and structs
obey) would be nice, too.



Jul 23 '05 #361
REH wrote:
Not all of us do "regular application programming." I write
mission-critical systems. In such an environment, it is non-sense NOT to
define ranges for data types that have them. I would rather it "failed
loudly" when a variable strayed out of range and raised an exception I can
recover from, then continuing to run, causing unknown or undefined behavior.

If you are having for loops with arrays in mind, a simple high level
safe C++ solution exists. Consider:
#include <algorithm>
#include <vector>

inline int doubleF(const int &arg) { return 2*arg; }

// ...

vector<int>some Array(10, 1);

// ...

transform( someArray.begin (), someArray.end() ,
someArray.begin (), doubleF );
This can't ever be out of bounds.

--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #362
REH

"Ioannis Vranos" <iv*@remove.thi s.grad.com> wrote in message
news:1110632256 .180589@athnrd0 2...
If you are having for loops with arrays in mind, a simple high level safe
C++ solution exists. Consider:
#include <algorithm>
#include <vector>

inline int doubleF(const int &arg) { return 2*arg; }

// ...

vector<int>some Array(10, 1);

// ...

transform( someArray.begin (), someArray.end() ,
someArray.begin (), doubleF );
This can't ever be out of bounds.

Much more just array accesses. Variables of particular units that must stay
within range (i.e., lat/long, BAMS, radians, velocities, altitudes, depths,
etc.). I'm not saying this can't be done in C++, because I've done it.
It's just easier in Ada.

Jul 23 '05 #363
Pascal Obry <pa****@obry.or g> writes:
This is not ok, P3 deeper than PA.

<<
procedure Demo is

type PA is access procedure;

procedure P (Proc : in PA) is
begin
null;
end P;

procedure P1 is
begin
null;
end P1;

procedure P2 is
procedure P3 is
begin
null;
end P3;
begin
P (P3'Access);
end P2;

begin
null;
end Demo;

However, it will be legal to pass a nested procedure in Ada 2005,
and GNAT already supports that. The rules still prevent dangling
pointers:

procedure P (Proc : access procedure(...)) is
begin
Proc;
end P;

procedure P2 is
P2_Local: Integer := 0;
procedure P3 is
begin
P2_Local := P2_Local + 1;
end P3;
begin
P (P3'Access);
end P2;

In Pascal's example, P can assign Proc into a global variable, and it
can be called after P2 returns, which is why it is forbidden to pass
P3. In my example, on the other hand, you can pass P3, but P cannot
assign Proc into a global variable. Either way, no dangling pointers,
unless you play some low-level tricks.
Can templates recurse?


Yes.


I think he meant "can generic instantiation be recursive", and the
answer is "no, it cannot". A generic procedure can call itself,
but that's not the same thing.
Can you program "const correct"? Eg. if you declare a member function
as const the compiler will help you not mutate the object or call any
functions that do. Also, if you pass a parameter as a const reference,
you will not be able to mutate the object the parameter references.


Not sure to understand everything. But yes, if you have:

Value : constant String := "whatever";

It will never be able to mutate Value.


.... and 'in' mode parameters can't be modified, and you can't modify
what an access-to-constant points at.

I think it's a bit more difficult to "cast away const" in Ada,
and the results can be bad news.

- Bob
Jul 23 '05 #364
Falk Tannhäuser <fa************ *@crf.canon.fr> writes:
I believe Ada also has exceptions, but I don't know if
they work in the same manner. Does Ada have some equivalent
of C++ constructors and destructors?


Yes. I believe that the C++ exception design was based on Ada
exceptions, and the Ada finalization stuff was based on the C++
features. The differences in these areas are fairly minor.
I guess the biggest one is that a C++ exception is a first-class
object, so you can pass extra information along with a thrown exception
in a straightforward way, whereas in Ada, the mechanism for passing
extra information is an ugly kludge.

Another difference is that Ada doesn't rely so heavily on constructors
-- there is something like a constructor in Ada, but the *usual* way to
create objects is simply to call a function that returns one, as in:

X: Int_Set := Empty_Set;
Y: constant Int_Set := Singleton_Set(1 7);

- Bob
Jul 23 '05 #365
Ki*******@SpamC op.net (Larry Kilgallen) writes:
Even Bliss has nested functions. What Ada has that Pascal has in addition
to nested functions is uplevel addressing, allowing an inner function to
access data declared in outer scopes.


Heh? Pascal has that. In fact, practically every programming language
outside the C family has this feature. It's quite useful -- almost
essential in multi-threaded programs.

- Bob
Jul 23 '05 #366
Peter Koch Larsen wrote:
I do not believe that to be the problem. There is a standard and there are
commercial libraries out there to test conformance. The problem rather
lies in other areas such as:

- compiler vendors wanting to be backwards compatible.
- compiler vendors wanting to get a grip on their customers by ofering
"extensions " to the language.
- compiler vendors who don't care if their product is standards-compliant.
How very true.
By 1990 or so when compilers conforming reasonably closely with the C
standard became available, it appears likely that essentially all new
development was being done in Ada. Under the circumstances, it would be
rather surprising if the C code was ever rewritten into standard C.


On the last project I was working with a 3rd party library which had not
a single "const" in its header files - probably to be compatible with old
compilers. So a major "savety" feature of C89 was still missing in
current code - and affected our current development - since I has to use
that library.


You could use another library out there. Cars are not bad just because one
manufacturer ships buggy cars out.


It was a very special lib with only a very few alternatives out there.
The most compatible C/C++ compiler AFAIK is digital mars
(http://www.digitalmars.com) with "only" 4 C99 features missing:
(http://www.digitalmars.com/ctg/ctgLa...unimplemented).

But even digital mars aims only at the C++98 and not the current C++
2003. And there are still 4 features missing:
(http://www.digitalmars.com/ctg/ctgLa...unimplemented).
Did you have a look at Comeau C++?
No. Got a link to have a look?
Maybe just maybe - if there realy was any standart compiler available -
but
there isn't - the C/C++ compiler vendors are allways one release behind
the
actual ISO standart.


If you look at C++ (i can't comment on C), all major vendors i know of
have a high level of compliance.


For the '98 standart yes - but how about the '03 standard. As I said - one
release behind.

And they havn't got 100% compliance - as the Ada compiler vendors have. And
they can indedd claim that - Ada has the ACATS test - pass the test you are
100% compliant - fail the thest and (almost) no customer will consider your
offer.
By contrast, comparing modern C++ to the pre-standard C shows _large_
improvements in nearly all areas. This is due in part to the changes in
the language itself, but perhaps even more so to improved understanding
of how to use the language.


True - the former slim languages designed by individuals have become fad
languages desined by the ISO commitie ;-). This is simply not true.
Shure it is true: The C++ ISO standard has ruffly 200 pages more then the
Ada ISO standard. The C standard is a few pages shorter - but C hasn't got
object orientation, concurency, real time and distributed system included.
The "ISO commitie" you refer to consists of
people using C++ in daily life.


So are the Ada commitie memebers. Still Ada was/is bashed for beeing a
commitie language and C++ isn't.
It is true that a programming language need some minimum features set to
be
usefull. And that feature set is a lot larger then most belive. If a
successfull language does not provide that set it will be bolted on
later. If anything the current C/C++ ISO standards clearly show that the
advocates
for slim languages hat been wrong all along.


I have to disagree again. C/C++ has been most succesfull as a language if
you measure that by the number of applications written in that language.


Shure C/C++ are successfull I never said any different - I just pointed out
that C/C++ are not slim and lightweight languages any more. They have
become fat over time. Only the fat does not show - because theree so many
implit features which only show when you read the ISO standart itself.

And since the very successfull C/C++ have become as big as they are I
rightfully claim the the advocates for slim languages hat been wrong all
along.

But prove me wrong and show me any successful slim language - which has not
become fat (either by language or by build in library) withing 10 years of
becomming successfull.

Martin
--
mailto://kr******@users. sourceforge.net
Ada programming at: http://ada.krischik.com

Jul 23 '05 #367
Martin Krischik wrote:
For the '98 standart yes - but how about the '03 standard. As I said - one
release behind.

C++03 is C++98 bug fixed. You can have a look at the list of fixes:

http://www.acceleratedcpp.com/author.../revisions.pdf
And they havn't got 100% compliance - as the Ada compiler vendors have.

Today in the latest compiler releases of the major vendors, compliance
is at least >98% (*there are* 100% compliant implementations ).
And
they can indedd claim that - Ada has the ACATS test - pass the test you are
100% compliant - fail the thest and (almost) no customer will consider your
offer.

There are compliance tests for C++ too.

--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #368
Simon Wright wrote:
Pascal Obry <pa****@obry.or g> writes:

CTips <ct***@bestweb. net> writes:

protected type Atomic_Integer is
procedure Increment;
private
Value : Integer;
end Atomic_Integer;
-- Implementation
protected body Atomic_Integer is
procedure Increment is
begin
Value := Value + 1;
end Increment;
end Atomic_Integer;
Will that generate:
L0:
lwlock temp,&Value
add temp,temp,1
stwcond temp,&Value
if( failed ) goto L0;
or will it generate something much more heavy-weight.


Google shows me lwlock as a C function in the PostGres support groups;
I don't know what machine architecture has these instructions? PowerPC?


Yes, and alpha.

It could be used by any compiler as part of a low-level
implementation, of course, but it's hardly likely that a C compiler
could use it off its own bat. Why whould it want to unless you the
programmer tells it to?

If you're talking about assembler inserts in C -- for Pete's sake, we
can insert assembler in Ada as a last resort if it's needed.
Can you do the following in Ada: use an assembler inset for just stwcond
and lwlock, and use C for everything else, and then get the expected
assembly code.
What happens with lwlock about priority inversion?
You don't need it. Thats one of the big advantages about lock free schemes.
No protected type implementations will be so light.


Umm ... look at the set of lock-free data-structures out there. Quite
heavy-weight structures can be implemented, including a queue where a
thread can be adding elements while other threads are removing elements.
Jul 23 '05 #369
REH wrote:
"Ioannis Vranos" <iv*@remove.thi s.grad.com> wrote in message
news:1110609321 .686344@athnrd0 2...

Myself thinks though that this whole range specialisation thing is
non-sense for regular application programming at least.

Indeed. :-)


Not all of us do "regular application programming." I write
mission-critical systems. In such an environment, it is non-sense NOT to
define ranges for data types that have them. I would rather it "failed
loudly" when a variable strayed out of range and raised an exception I can
recover from, then continuing to run, causing unknown or undefined behavior.


Thats another problem with Ada's run-time checking. If you're using it
in an environment where the hardware may "fail" [e.g. alpha particles
randomizing memory], the checks are quite often in the wrong place.

For example, look at the Ada equivalent of the following code.
typedef enum {0, 1, 2, 3} four_val;
four_val x;

x = (four_val) some_int;
....
assert( x < 4);

The compiler will drop in a check at the cast to ensure that the wrong
value is not getting stored into x. Then, it will proceed to eliminate
the check that x < 4, because it knows that 0..3 are the only legal
values of x. However, if there is a hardware bug, the value of x will
get changed between the definition point and the use point.

When bringing up hardware, I like to have a little more control over
where the run-time checks are going to be placed. This is another niche
situtation in which the compiler's "automatic" checking does the wrong
thing.
Jul 23 '05 #370

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

Similar topics

20
2364
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
1828
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
2001
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
4379
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
2865
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
1715
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
3896
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
9531
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
10237
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10018
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7553
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
6795
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();...
0
5446
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4120
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
3735
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2928
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.