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

  • Thread starter Turamnvia Suouriviaskimatta
  • Start date
D

dave

Ioannis said:
More precisely, it is a CLI compliant VM environment which provides a
fairly large, high-level, Windows-oriented API which is common for all
languages.


However C++/CLI design ideals, are not only C++ to be used for
application programming as a first class citizen CLI (.NET) citizen, but
*also* for .NET library writing (managed dlls).


With C++/CLI and VC++ 2005, C++ becomes the systems programming language
of CLI (and .NET).


You may take a look at these:

http://msdn.microsoft.com/msdnmag/issues/05/01/COptimizations/default.aspx

http://pluralsight.com/blogs/hsutter/archive/2004/10/05/2672.aspx

http://blogs.msdn.com/branbray/archive/2003/11/07/51007.aspx

http://www.accu.org/conference/pres...Relevant_on_Modern_Environments_(keynote).pdf



And a page of mine:

http://www23.brinkster.com/noicys/cppcli.htm



With C++/CLI, C++ has two worlds: The unmanaged world and the managed
world.

In the managed world every CLI (.NET) feature is provided separately
from the unmanaged world features.

ADA.net? Surely not!!
 
R

Robert A Duff

Still looking for this number if anybody has it handy.

Not sure which number you're looking for...

The ACATS has been around since the 1980's (although in those days it
was called ACVC; it got renamed ACATS around the time Ada 95 became an
ISO standard). It gets updated from time to time, as new language
revisions come out, and as the language committee issues rulings about
some fine points of the language.

As far as I know, all Ada compiler vendors take it seriously, and ensure
that their compilers pass 100% of the test suite. My company (Sofcheck,
Inc.) runs the ACATS every night, so we notice any regressions quickly.
We don't normally release a compiler that doesn't pass. I believe
AdaCore (the folks who produce the gcc version of Ada (GNAT)) do the
same.

As I said elsewhere, passing 100% of the ACATS, or 100% of any other
test suite, does not guarantee the absense of bugs (obviously).
These points certainly "lessen the gap" then (if there was one)
and make it much closer to the C++ situation then.

What is the C++ situation? Is there a conformance test suite available?
Is it free? What about C (same questions)? (Sorry, if you already
answered that.)

By the way, the idea that Ada(tm) compilers had to pass some tests is
long, long gone. It was a fairly silly idea, anyway, and totally
unenforceable. Nobody's stopping anybody from producing a compiler for
Ada-except-some-diffs, or C++-except-some-diffs, for that matter.

- Bob
 
E

Ed Falis

As far as I know, all Ada compiler vendors take it seriously, and ensure
that their compilers pass 100% of the test suite. My company (Sofcheck,
Inc.) runs the ACATS every night, so we notice any regressions quickly.
We don't normally release a compiler that doesn't pass. I believe
AdaCore (the folks who produce the gcc version of Ada (GNAT)) do the
same.

Yes, we do.
As I said elsewhere, passing 100% of the ACATS, or 100% of any other
test suite, does not guarantee the absense of bugs (obviously).

Agree wholeheartedly.

- Ed
 
J

Jean-Pierre Rosen

Jerry Coffin a écrit :
Let's address the Ada side first. Official Ada validation was done
under the auspices of NIST, who delegated this task to the Ada Joint
Program Office. The AJPO ceased to exist years ago, and the job was
never turned over to anybody else when that happened. Meanwhile, NIST
has discontinued _all_ of its compiler validation programs, not just
the Ada program. Currently, both the ISO standard at a number of FIPS
pubs _require_ Ada compilers to be officially validated, but at least
in the US, there is absolutely NO agency to do that.
I can assure you that there is still one official ACAL (laboratory for
performing validation): Adalog, that's my company!

OK, it's not in the US. So what? Ada is an international standard.
 
D

dave

dave said:
Well I never! Gore blimi! You what! and, well... er... yes.

If I had not seen it with my own eyes...

Nme. God Bless.

After thought:

Microsoft + CLI == Not Mission Safe

Microsoft + CLI + ADA == Bad for ADA
 
I

Ioannis Vranos

Jeff said:


Unfortunately this does not load in here, so I viewed it through
google's cache. Also the ftp site does not work.


Perhaps they do not allow connections from outside the US so as to
protect the precious .NET-enabled Ada. :)


In any case, I suspect this will be fine to create .NET applications,
however I suspect that it cannot produce 100% verifiable .NET code (the
equivalent of VC++ 2005 /clr:safe), that is 100% managed code.


That is, it must be something like VC++ 2003 for C++.


In addition, I suspect it does not provide any designer support (RAD)...
 
D

Dr. Adrian Wrigley

Falk said:
Dr. Adrian Wrigley said:
But what of features not present in either?
[...]

associative arrays (from Perl)

Wouldn't that be std::map in C++?

and in Ada 2005,

Ada.Containers.Hashed_Maps and Ada.Containers.Hashed_Maps

I have probably missed a trick in the C++, but I couldn't get
std::map code to compile (except in the trivial cases):

#include <map>

struct compoundindex {
int a, b, c;
};

int main()
{
std::map<compoundindex, float> hash;
compoundindex fred = { 1, 2, 4 };

hash[fred] = 0.123;
}

cpptest.cpp: In function `int main()':
cpptest.cpp:14: error: `main()::compoundindex' uses local type
`main()::compoundindex'
(8 more lines of errors here!)

(what is the simplest C++ code to get this intent?)
--
The Ada associative arrays from the new draft standard
are specified as something like:

generic
type Key_Type is private;
type Element_Type is private;
with function Hash (Key : Key_Type)
return Hash_Type is <>;
with function Is_Equal_Key (Left, Right : Key_Type)
return Boolean is "=";
with function "=" (Left, Right : Element_Type)
return Boolean is <>;
package Ada.Containers.Hashed_Maps is...


Which clearly won't work unless you can find the three
function generic parameters. I don't see how this can be
used easily in a generic context.

I don't think I am being *that* unreasonable in asking for arrays
indexed by arbitrary types, without jumping through hoops :)
 
D

Dr. Adrian Wrigley

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.

isn't uplevel addressing usually zero cost? Are you saying it is
expensive whenever you use it? Or expensive on all programs, whether
or not it is used? Is it absent from C++ because of cost?
(I'm sure Robert understands this far better than I!)
 
I

Ioannis Vranos

Dr. Adrian Wrigley said:
#include <map>

struct compoundindex {
int a, b, c;
};


inline bool operator <(const compoundindex &a, const compoundindex &b)
{
return (a.a<b.a && a.b<b.b && a.c<b.c)? true: false;
}

int main()
{
std::map<compoundindex, float> hash;
compoundindex fred = { 1, 2, 4 };

hash[fred] = 0.123;
}



As a rule of thumb remember that most standard containers and algorithms
require the presence of operator <.


From a design perspective, in the example above, it is better to make
operator< a member of the struct. I made it a global function, in case
you want a POD struct.
 
P

Peter Koch Larsen

"Dr. Adrian Wrigley" <[email protected]> skrev i en
meddelelse
Falk said:
Dr. Adrian Wrigley wrote:

But what of features not present in either?

[...]

associative arrays (from Perl)

Wouldn't that be std::map in C++?

and in Ada 2005,

Ada.Containers.Hashed_Maps and Ada.Containers.Hashed_Maps

I have probably missed a trick in the C++, but I couldn't get
std::map code to compile (except in the trivial cases):

#include <map>

struct compoundindex {
int a, b, c;
};

int main()
{
std::map<compoundindex, float> hash;
compoundindex fred = { 1, 2, 4 };

hash[fred] = 0.123;

First off, std::map is not hash-based. It is a sorted container. Now in
order to use this, you need a comparing function. It can be the "standard"
ordering function for your key or it can be a user specified function.
}

cpptest.cpp: In function `int main()':
cpptest.cpp:14: error: `main()::compoundindex' uses local type
`main()::compoundindex'
(8 more lines of errors here!)

You must have snipped the most interesting errormessage.
(what is the simplest C++ code to get this intent?)

What you need here is a comparator:

bool operator<(compoundindex const& lhs,compoundindex const& rhs)
{
.....
}

And the map should work.
--
The Ada associative arrays from the new draft standard
are specified as something like:

generic
type Key_Type is private;
type Element_Type is private;
with function Hash (Key : Key_Type)
return Hash_Type is <>;
with function Is_Equal_Key (Left, Right : Key_Type)
return Boolean is "=";
with function "=" (Left, Right : Element_Type)
return Boolean is <>;
package Ada.Containers.Hashed_Maps is...


Which clearly won't work unless you can find the three
function generic parameters. I don't see how this can be
used easily in a generic context.

I don't think I am being *that* unreasonable in asking for arrays
indexed by arbitrary types, without jumping through hoops :)

But I do! How can you index without at least knowing if two values are
different or the same?
The C++ standard will have a hash-based container later. Those interested in
having one can download one from e.g. boost (I believe this container also
to be implemented by boost and prbably several others).
/Peter
 
?

=?ISO-8859-1?Q?Falk_Tannh=E4user?=

Dr. Adrian Wrigley said:
I have probably missed a trick in the C++, but I couldn't get
std::map code to compile (except in the trivial cases):

#include <map>

struct compoundindex {
int a, b, c;
};

int main()
{
std::map<compoundindex, float> hash;
compoundindex fred = { 1, 2, 4 };

hash[fred] = 0.123;
}

C++ associative containers (map, set, multimap, multiset) require
a "strict weak ordering" for their key types. In the present case,
it is enough to define the following 'operator<' to induce a total
ordering:

bool operator<(compoundindex const& x, compoundindex const& y)
{
if(x.a < y.a) return true;
if(x.a == y.a)
{
if(x.b < y.b) return true;
if(x.b == y.b)
return x.c < y.c;
}
return false;
}

Alternatively, if there is no natural definition for a general-purpose
operator< for the key type in question, it is possible to create a
comparison functor and to instantiate the container with it as
supplementary template parameter.
In either case, the container implementation uses the order to store its
elements in a balanced tree, so that element access becomes possible
with logarithmic complexity regarding to the number of elements currently
in the container.

Hash-based associative containers (guaranteing constant-time access as
long as there are no key collisions) are not (yet) provided by the
standard library but are widely available through third party / extension
libraries.

Falk
 
L

Larry Kilgallen

Oh, sorry, I must have thought you said "...in addition to what Pascal
has..." or something. My bad.

Anyway, nested functions are really nested in any useful sense if you
can't do uplevel addressing, right?

I much prefer that capability, but in Bliss (which lacks uplevel addressing)
there is some benefit provided by just the reduced visibility of the
nested function. I know for sure that I can call my nested function
RETRIEVE_STATUS without worrying about a conflict with something else
of the first name.

This is _certainly_ not a Bliss vs. Ada argument, but for me it is
a Bliss vs. C argument.

Please remember, however, that I only mentioned it because you asked :)
 
L

Larry Kilgallen

But what if you actually need uplevel addressing ?

Why would one presume that users of uplevel addressing actually need
thread-private storage ? Thread-private storage would give just
a single instance per thread, not multiple nested instances per
thread.
 
D

Dr. Adrian Wrigley

Alternatively, if there is no natural definition for a general-purpose
operator< for the key type in question, it is possible to create a
comparison functor and to instantiate the container with it as
supplementary template parameter.

the problem as I suggested in my previous post is that you have to
pass in the comparison operator or hash function down the tree
of template/generic instantiation, (composing them along the way)
if you want to use maps/hashes. If the necessary functions are
not passed in and built up, you can't instantiate the map/hash.
This means that you can't write an implementation of a template/generic
function using a map/hash without changing some/all the implementations
and interfaces up the instantiation tree (am I right?). Obviously this
may not be possible, for example in large a multi-team or multi
language project. If you changed from a map to a hash, you'd have
to change all the interfaces to pass the hashing function instead
or as well as the comparison operator.

In Ada, a private (nonlimited) generic formal type guarantees
an equality operation and assignment is defined for the type.
These are the only logical requirements for an associative array.
I guess an efficient hash/map library could be written for
private nonlimited generic formals, but neither std::map nor
hashed maps meet this less restrictive requirement.

Put another way, neither language has minimally restrictive
associative arrays in their (or their standard library) specification.
 
J

jtg

Turamnvia said:
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?

I had the same problem several years ago.
I was learning Ada from tutorials (www.adahome.com) and online
articles. They were nice and I could get the ideas quickly, but
they were rather shallow and I just could not find answers to
many questions.

After buying one poor book (just the only I could find in local
bookstores) I decided to search for a good book in online bookstores.
I chose "Ada as a second language" by Norman Cohen and I am very glad
with it. All the questions that bothered me (some for months) were
answered in no time. AFAIR always when I needed to know something
about Ada I could find it in this book (well, one exception:
I could not find any information about preprocessor, but some
Ada programmers claim you don't need preprocessor in Ada).

As the title suggests, the book assumes that the reader is already
a skilled programmer :)
In the book there are many comparisons to C, C++ and some other
languages. If an Ada feature is similar to something in C or C++,
the book mentions it to help pick the idea. If there are differences,
the book mentions them too, to help avoid potential pitfalls
or correct "bad habits", i.e. ways which are natural in one
language but are not the right way to do sth in Ada. So I think
the book would be as useful for you as it was for me.

Is it difficult to move from C/C++ to Ada? Maybe I can tell
you what you may expect (from my own experience only).
When you write in Ada, it is much, much easier to get bugless
program once you manage to compile it (of course if you make
use of Ada features). However, trying to compile an Ada code may be
sometimes very, very frustrating, when the compiler complains
about sth, you look into the code and cannot find out what a strange
rule you are breaking this time in this particular place.

And in Ada you must write a lot more.
You must declare everything, you must be explicit, you must obey
the rules which sometimes seem stupid.
And you must forget about these handy i++, --j, i+=a etc.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,667
Latest member
DaniloB294

Latest Threads

Top