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 29705
Falk Tannhäuser wrote: Perhaps the closest way you can get to this in C++ is
std::vector<foo _type> Data; ... std::for_each(D ata.begin(), Data.end(), DoSomething);
where "DoSomethin g" evaluates to a so-called "function object" having an "operator() " accepting a (reference to) "foo_type".
Yes you can write completely safe, bullet-proof code in C++ and without
sacrificing efficiency (and some times even improving it!) by using the
high level C++ constructs. Examples are: find family (which includes
find_if etc), search family, generate, fill, for_each, count, mismatch,
equal, transform, copy, swap, replace, remove, unique, rotate, sort,
bound, merge, partition, includes, set (like set_union), heap (like
make_heap - makes sequences behave as heaps), comparisons (like min,
max, lexicographical _compare), permutation, etc families.
We can say it is an entirely completely safe, high level language of its
own, and in this way you may never use loops for most things!
--
Ioannis Vranos http://www23.brinkster.com/noicys
Jim Rogers wrote: #include <iostream> #include <vector> #include <ctime> #include <algorithm>
int main() { using namespace std;
vector<int> vec(1000);
// Seeds the random number generator srand(time(0));
// Use rand() to fill vector with values // As you see the operation is entirely safe. generate(vec.be gin(), vec.end(), rand);
vector<int>::si ze_type i;
// Finds the first index where a value is smaller than 1000 // in low level style for(i=0; i<vec.size(); ++i) if(vec[i]<1000) break;
i==vec.size()? cout<<"No number <1000 was found\n" :cout<<"Number <1000 found at index "<<i<<"\n"; }
The idioms are somewhat different. For instance, the Ada for loop does not iterate one past the end of the array, nor is the value of the loop control variable visible outside the loop.
I did not see where you set the range of values for your random number type. I am generating integer values in the range of 0 through 10,000.
I used the default range.
with Ada.Text_Io; with Ada.Numerics.Di screte_Random;
procedure Random_Fill is type Rand_Values is range 0..10_000; package My_Rand is new Ada.Numerics.Di screte_Random(R and_Values);
Seed : My_Rand.Generat or; subtype Index_Type is Natural range 1..1000; Vec : array(Index_Typ e) of Rand_Values; Found : Natural := 0; begin My_Rand.Reset(S eed); -- seeds the random number generator
-- fill the array with random values in the range of 0 -- through 10,000 for I in Vec'range loop Vec(I) := My_Rand.Random( Seed); end loop;
-- finds first index where a value is less than 1000 for I in Vec'range loop if Vec(I) < 1000 then Found := I; exit; end if; end loop; if Found > 0 then Ada.Text_Io.Put _Line("Number < 1000 found at index" & Natural'Image(F ound)); else Ada.Text_Io.Put _Line("No number < 1000 was found"); end if; end Random_Fill;
Yes but what happens if you want to use the indexed found with the
associated value (ot could be inside a string for example) in an
associative container like a map?
That is, find the index and then use the index to add the value in a
map. I suppose you would create a separate procedure for this in which
you would pass the array along with the container and perhaps along with
the item to be found, just for one such operation!
--
Ioannis Vranos http://www23.brinkster.com/noicys
Ioannis Vranos wrote: Yes you can write completely safe, bullet-proof code in C++ and without sacrificing efficiency (and some times even improving it!) by using the high level C++ constructs. Examples are: find family (which includes find_if etc), search family, generate, fill, for_each, count, mismatch, equal, transform, copy, swap, replace, remove, unique, rotate, sort, bound, merge, partition, includes, set (like set_union), heap (like make_heap - makes sequences behave as heaps), comparisons (like min, max, lexicographical _compare), permutation, etc families.
We can say it is an entirely completely safe, high level language of its own, and in this way you may never use loops for most things!
More accurately described as "entirely completely safe, high level world
of its own".
--
Ioannis Vranos http://www23.brinkster.com/noicys
In article <42********@new s.alphalink.com .au>, Song Yun Zhao <mr************ @yahoo.com.au> writes: Larry Kilgallen wrote: In article <1110052142.832 650@athnrd02>, Ioannis Vranos <iv*@remove.thi s.grad.com> writes:
Ludovic Brenta wrote:
The bug in the C++ library was that I was mistakenly reusing the loop variable after the loop, instead of the intended variable. Of course, the loop variable was an index pointing after the end of the buffer.
It looks like the code was not ISO C++ compliant.
In that case, it looks like the compiler failed to detect that shortcoming.
A real man's compiler
http://somewhere.fscked.org/rmcc/
:)
The VMS primitive debugger Delta (used to debug the system bootstrap
but not much else) is famous for having just one error message:
Eh ?
At one point somebody inside DEC created a fake Delta support Notes
conference with various questions about the way Delta works, each
receiving the response:
Eh ?
Jerry Coffin wrote: If I made the kind of unfair generalizations sometimes made by some Ada advocates, I'd say that Ada programmers only look at the surface, and don't consider the deeper meaning of things. :-)
Look past the toolbox itself, and consider the systems on which it runs. To save you the trouble of looking it up again, I'll point it out: X running on top of either Windows or UNIX.
Now do you suppose some C and C++ might be involved?
Sorry, but if you make a link to a news item /about/ a particular tool,
at least /I/ am going to believe that you are making a point about the
tool and not the OS it works on! Why not provide a link directly to a
page about X running on top of either Windows or UNIX?! :-)
Cheers
-- Martin
Ioannis Vranos <iv*@remove.thi s.grad.com> wrote in news:1110429670 .232319
@athnrd02: Yes but what happens if you want to use the indexed found with the associated value (ot could be inside a string for example) in an associative container like a map?
That is, find the index and then use the index to add the value in a map. I suppose you would create a separate procedure for this in which you would pass the array along with the container and perhaps along with the item to be found, just for one such operation!
I assume the container type is already defined, including a procedure
to insert new values into the container. I would simply call the
insert or add procedure for that container, passing in the
appropriate information. This is no different than calling a
member function for a class in C++.
Jim Rogers
Goeie dag Georg
Thanks for all the replies, I'll stop wasting bandwith with trivial
questions and go find out myself.
Groete
Hans
xpyttl wrote: "Martin Dowie" <ma**********@b topenworld.com> wrote in message news:d0******** **@titan.btinte rnet.com...
What on earth would the C advocate say!! ;-)
Leave me alone, I've got work to do!
Surely...
Leave me alone, I've got debugging to do!
;-)
Jim Rogers wrote: I assume the container type is already defined, including a procedure to insert new values into the container. I would simply call the insert or add procedure for that container, passing in the appropriate information. This is no different than calling a member function for a class in C++.
How can this be done in Ada?
As it can be seen here, the bullet-proof high level facilities are used. :-)
#include <iostream>
#include <vector>
#include <ctime>
#include <algorithm>
#include <functional>
#include <map>
int main()
{
using namespace std;
vector<int> vec(1000);
map<int, int> iimap;
// Seeds the random number generator
srand(time(0));
// Use rand() to fill vector with values
// As you see the operation is entirely safe.
generate(vec.be gin(), vec.end(), rand);
// Finds the first occurrence of an int smaller than 1000
vector<int>::co nst_iterator p= find_if(vec.beg in(), vec.end(),
bind2nd(less<in t>(), 1000) );
int index= p-vec.begin();
// Stores the index and the value in a map
iimap[index]= *p;
cout<<index<<": \t"<<iimap[index]<<"\n";
}
--
Ioannis Vranos http://www23.brinkster.com/noicys
Wes Groleau wrote: ji************* *@worldnet.att. net wrote: The simple loop will always be an infinite loop unless you break out early. The Ada reserved word used to break out of a loop is "exit". In Ada "exit" does not exit the program, only the enlcosing loop. Or (for nested loops), each loop can have a name, and the exit statement can exit out of two or more nested loops by using the name of the level to get out of.
Java has a construct that can do something like that. Does C++ ?
No. However, a 'return' from the middle of a function
(even from within the deepest nested loops) is possible.
Another way, especially designed for error handling, are
exceptions which allow "returning" from many function call
levels while cleaning up and leaving the program in a well-
defined, clean state through calling the destructors of all
stack-based objects on the way. However this requires some
care from the programmer - you have to code in an "exception-
safe" manner.
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?
Falk 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: 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: 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: 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();...
|
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: 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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |