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
Robert A Duff wrote: 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
Yeah, and don't ask what it costs you. I'd carefully forgotten about all
the grungy details about displays and static/dynamic chaining, and you
had to remind me. I particularily like solutions that reserves a
register for the top-of-display/top-of-static-chain. Thats right - blow
away a register for that. And then of course the cost of
maintaining/walking those structures.
If you need thread-private storage, there are *much* cheaper solutions.
CTips wrote: 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.
Of course one could insert manual checks for those cases as well and it
is certainly possible to disable the automatic checks (in fact, I'd
argue a bit with some others about the "cheapness" of these checks. It
certainly varies from compiler to compiler and program to program but in
a moderate sized set of applications (~150K SLOC) I have measured the
penalty as high as 10-15%.). The automatic checks are available. You
can use them just during development and disable for production or if
you can live with them, then you can leave them on during
production..But , arguing that it is bad for the language to provide for
them because it might not be what you want is like arguing that the C++
standard should not include any references to floating point since
sometimes you have a processor that does not have an FPU and then you'd
feel more comfortable rolling your own floating point.
On Sat, 12 Mar 2005 12:46:11 -0500, CTips <ct***@bestweb. net> wrote: 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);
type Four_Val is range 0 .. 3;
X : Four_Val;
begin
X := Four_Val (Some_Int);
...
pragma Assert (X < 4, "Something is seriously honked here");
-- Currently supported by GNAT; part of Ada 2005
-- Or write your own subprogram in Ada 95 as I did for AUnit
Do_Something_Wi th (X);
Sounds to me as though you just like to argue, because this one was pretty
silly.
- Ed
CTips wrote: 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.
Well actualy: since 4 is not a valid value for the enum four_val the Ada
compiler won't compile the code - Ada does not automaticy convert enums
into integer.
The way you would do it in Ada is
pragma Assert (x'Valid);
The 'Valid attribute checks if a variable contains a valid value.
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.
'Valid is used when a variable may contain an invalid value because of
calling a non Ada function or maybe a hardware problem :-) .
You may also use "pragma Volatile" if you fear that a variable chances its
value. Which is the very same in C89: without "volatile" the optimizer may
remove a access to a variable. No difference between C and Ada once
optimizer kicks in.
But then: most C programmers fear the optimizer while most Ada programmers
welcome the optimizer.
With Regards
Martin
--
mailto://kr******@users. sourceforge.net
Ada programming at: http://ada.krischik.com
Ioannis Vranos wrote: 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
Ups, right C++ 2003 is only the 5 year bug fix. But then: that isn't good
news. The C++ 98 is out for 7 years and you still have to look hard to find
a fully compliant compiler.
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 ).
I still look for one. Not trolling here - I would realy love to see at least
one fully compiant compiler.
As for major vendors: MS-C++ 7.1 and digital mars do not know about
"export". In my book 98% does not apply when a hole keyword is missing.
Side note: All Ada templates are "export" - so it is possible implement
export.
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.
With ISO number? If so tell me - I love to know. Without ISO: better then
nothing but not as helpfull to get companies like M$ to comply.
With reagards
Martin
--
mailto://kr******@users. sourceforge.net
Ada programming at: http://ada.krischik.com
CTips <ct***@bestweb. net> writes: 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.
That's like saying "another problem with my refrigerator is that it
doesn't cook food". Ada's run-time checking is not intended to deal
with hardware failures of this nature. Neither are if statements in Ada
or C++.
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.
That could happen whether or not you have automatic run-time checks.
And in the above, there is no guarantee that x<4 in the code following
the assert -- the alpha particle could hit just after the assertion.
Just as in "if (X < 4) { ... X ... }", the second reference to X might
produce 17, if hardware can fail.
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.
You have no such control in either language under discussion. Compilers
can and do optimize code based on the assumption that the hardware is
perfect. If you don't like that, you have to write in assembly
language, or dump out the assembly language and make sure it does what
you want. Or use redundant hardware, or wrap the thing in lead, or any
number of other techniques that have nothing whatsoever to do with Ada
or C++ or run-time checking!
- Bob
Martin Krischik wrote: Today in the latest compiler releases of the major vendors, compliance is at least >98% (*there are* 100% compliant implementations ).
I still look for one. Not trolling here - I would realy love to see at least one fully compiant compiler. http://www.comeaucomputing.com
As for major vendors: MS-C++ 7.1 and digital mars do not know about "export". In my book 98% does not apply when a hole keyword is missing.
Side note: All Ada templates are "export" - so it is possible implement export.
Comeau supports export.
Regarding MS, upcoming VC++ 2005 (8) is even more compliant (>~99%) than
7.1.
They say that they do not support export though, because there is no
user demand (use) of it and it takes much work to implement it. There are compliance tests for C++ too.
With ISO number? If so tell me - I love to know. Without ISO: better then nothing but not as helpfull to get companies like M$ to comply.
Third party test suites as far as I know. MS strives for complete ISO
C++ conformance (except export).
--
Ioannis Vranos http://www23.brinkster.com/noicys
Martin Krischik wrote: Well actualy: since 4 is not a valid value for the enum four_val the Ada compiler won't compile the code - Ada does not automaticy convert enums into integer.
The way you would do it in Ada is
pragma Assert (x'Valid);
The 'Valid attribute checks if a variable contains a valid value.
Now that I am thinking of it, isn't it a value range?
int main()
{
enum four_val {a,b,c,d};
four_val x;
x = 4;
}
C:\c>g++ temp.cpp -o temp.exe
temp.cpp: In function `int main()':
temp.cpp:7: error: invalid conversion from `int' to `main()::four_v al'
C:\c>
--
Ioannis Vranos http://www23.brinkster.com/noicys
Ed Falis wrote: On Sat, 12 Mar 2005 12:46:11 -0500, CTips <ct***@bestweb. net> wrote:
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); type Four_Val is range 0 .. 3; X : Four_Val; begin X := Four_Val (Some_Int); ... pragma Assert (X < 4, "Something is seriously honked here"); -- Currently supported by GNAT; part of Ada 2005 -- Or write your own subprogram in Ada 95 as I did for AUnit Do_Something_Wi th (X);
Sounds to me as though you just like to argue, because this one was pretty silly.
- Ed
Did you compile it and see if the check was still in the generated code?
If it is, I'd start wondering about the quality of the compiler...
(unless there was something which disabled range propagation [or its
equivalent] for asserts...)
Martin Krischik <ma****@krischi k.com> writes: 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.
Now wait. Let's be fair. Sure, the ACATS test suite is a good thing.
But no test suite can ensure 100% compliance with the language
standard. Ada compilers do have bugs that are not caught by the ACATS!
Having a standard compliance test suite is an advantage of ADa,
but it's not a 100% guarantee of anything. (In fact, all Ada compiler
vendors I know of have huge regression test suites that go way beyond
ACATS.)
- Bob
P.S. Oops, I typed "ADa" above, instead of "Ada". I think I'll leave
that typo in, just to taunt the zealots who think spelling the name of
the language correctly is important. ;-) Come on folks, do you think
being pedantic about ADA vs. Ada will win converts? I think it adds to
the (mostly wrong) impression that Ada is all about rules and
regulations for no good reason. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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.
|
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...
|
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...
|
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...
|
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
| |
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
|
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
|
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...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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,...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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...
| |