473,395 Members | 1,577 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 28840

"Ludovic Brenta" <lu************@insalien.org> skrev i en meddelelse
news:87************@insalien.org...
Peter Koch Larsen writes:
"Ludovic Brenta" skrev i en meddelelse
procedure Proc (A : in String) is
begin
for J in A'Range loop
J := J + 4; -- illegal, J is constant inside the loop
end loop;
Do_Womething_With (J); -- illegal, J no longer exists
end Proc;
This is inherited from Pascal if I remember correctly. Of course,
good C++ style is to declare your variable in the loop.


Most of Ada's syntax is inherited from Pascal. In fact, Ada is
"Pascal done right", since Ada eliminated most of Pascal's problems
like separate compilation or the infamous "dangling else" problem. For
that matter, these problems also exist in C and C++.

It is true that, in ISO C++, loop variables declared in the for
statement are not visible outside the loop. However, the library I
was working on did make use of the loop variable after the loop, and
none of our 4 or 5 different C++ compilers complained about it.

Which brings me to the general question: is there any
standard-compliant C++ compiler in existence? Or are compilers only
"mostly compliant" or "close enough" or some other ill-defined term?


If you disregard the controversial "export" keyword, most recent compilers
are close to being 100% conforming (but might not be so "out-of-the-box").

By contrast, consider Ada's formal validation process, which is also
an ISO standard (ISO/IEC 18009 - Ada: Conformity assessment of a
language processor). In the 1980's, the DoD held the trademark "Ada",
and only validated compilers were allowed to call themselves "Ada
compilers". Now, the rules are more lax, but all compilers in
existence pass the validation suite. See:

http://www.ada-auth.org/acats.html
I will look into that one later.
* conditions cannot mix "and" and "or" without parentheses. Thus
there is no possibility that the programmer make wrong assumptions
about precedence of operators or order of evaluation.


This seems ridiculous. I would expect a programmer to know the
precedence rules or at least insert parentheses if they are in
doubt.


This is the crux of the problem. Assuming that the programmer "knows
the rules", "makes no mistakes" or "can be trusted" is a recipe for
disaster. One of the principles in Ada's rationale is to make
everything explicit, rather than implicit.


Do you also require parenthesis when mixing addition and multiplication? I
do not like that degree of nannying - a matter of taste, surely.
* the type system, when used appropriately, makes it possible for
the compiler to find semantic errors in addition to just syntax
errors. For example, you can declare that Numers_Of_Apples and
Numers_Of_Oranges cannot be mixed. This is not possible with C++'s
typedef.
I like that idea. It is possible using templates, of course. Is it
general enough? If you replace "apples" with "weight" and "oranges"
with "length", is it then permissible to multiply a length with a
weight but not add the two together?


Yes:

type Weight is digits 8 range 0.0 .. 900.0; -- 8 decimal digits of
precision
type Length is digits 8 range 0.0 .. 1000.0;

Now these types are incompatible. If you want to mix them, you need
to define the semantics and provide the appropriate operators:

type Weight_Length is digits 8 range 0.0 .. 900_000.0;

function "*" (Left : in Weight; Right : in Length) return Weight_Length;

Since you don't provide "+", there is no way to add a weight to a
length.

For a more general discussion of physical quantities in Ada, see:

http://home.t-online.de/home/Christ-.../Universe.html


I believe I will prefer the C++ solution - a template that copes with all
this stuff.
* conversions from floating point to integer types involve
rounding. The rounding is precisely and deterministically defined
by the ISO standard for the Ada language. Similarly,
floating-point and fixed-point types can be declared with known,
deterministic, guaranteed precision.
This point sounds as if it restricts the environments where Ada can
be used.


Do you mean that not all targets may implement the requested
precision? That is true but it is not a language issue. Ada
compilers are required to document which precision they support for
their targets.

And fixed-point types being really nothing more than integers, all
targets support them to some extent.
I sort of like this one as well - although raising an exception
seems to be to forgiving.


What other mechanism would you suggest?


Termination of the program. Some might argue that they can't tolerate such
an event. But can such an environment tolerate a faulty running program?
My conclusion is that there are some nice ideas out there, but that
they mainly protect against the "sloppy" programmer.


It is a mistake to assume that the programmer makes no mistakes.
Mistakes are a given fact of the human nature. Ada is designed with
this in mind.

A sloppy programmer will avoid Ada like the plague, because they
resent discipline in general and don't appreciate being taught
lessons. A good software engineer will be attracted to Ada because
she is a powerful ally.

--
Ludovic Brenta.


/Peter
Jul 23 '05 #51
"Peter Koch Larsen" writes:
If you disregard the controversial "export" keyword, most recent
compilers are close to being 100% conforming (but might not be so
"out-of-the-box").
Good. What kind of assurance does a C++ compiler user have?
Do you also require parenthesis when mixing addition and
multiplication? I do not like that degree of nannying - a matter of
taste, surely.


No, just when mixing "and" and "or".
For a more general discussion of physical quantities in Ada, see:

http://home.t-online.de/home/Christ-.../Universe.html


I believe I will prefer the C++ solution - a template that copes with all
this stuff.


Read the paper first; it does use templates (generics).
What other mechanism would you suggest?


Termination of the program. Some might argue that they can't
tolerate such an event. But can such an environment tolerate a
faulty running program?


That's what an unhandled exception results in. In avionics, where we
have no operating system and no run-time system, exceptions cannot
propagate and thus always result in program termination. When testing
the program, we prove that no exception is ever raised.

--
Ludovic Brenta.
Jul 23 '05 #52
Ioannis Vranos writes:
The restriction that you imply you desire, limits flexibility.
Of course. That's what all these stories about shooting yourself in
the foot mean.
Once again, I have nothing against learning Ada, however personally
I like the most powerful languages. The next thing I am going to
learn after C++ (because I haven't learned it all yet), is probably
some form of assembly language.
Yes, assembly is the most powerful and flexible language. That's why
all compilers emit assembler.
For example I like that I can do:
[...]

in Ada, you would use an overlaid array of characters, like this:

with Ada.Strings.Unbounded;
with Ada.Text_IO;
procedure Unsafe_Proc is
type Some_Class is record
S : Ada.Strings.Unbounded.Unbounded_String;
end record;

Obj : aliased Some_Class :=
(S => Ada.Strings.Unbounded.To_Unbounded_String
("This is a text message"));

Obj_As_String : String (1 .. Obj'Size / System.Storage_Unit);
for Obj_As_String'Address use Obj'Address;
begin
for J in Obj_As_String'Range loop
Ada.Text_IO.Put_Line
(Integer'Image (Character'Pos (Obj_As_String (J))) &
" " &
Obj_As_String (J));
end loop;
end Unsafe_Proc;
Here, Ada makes it explicit that unsafe programming is taking place.
First, Obj must be declared as "aliased", which means that two or more
paths can access it. In our case, Obj and Obj_As_String are the two
paths. This is another of Ada's nice safety-related features. Since
aliasing must be made explicit, the reader of the program knows up
front whether or not aliasing takes place. The reader of a C++
program has no such knowledge. Also, the writer of the program must
think twice, and understand the consequences if they make an object
aliased.

Secondly, the representation clause for Obj_As_String ("for
Obj_As_String'Address use ...") says exactly what is happening.

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.
I am sure that many ADA developers will say that this one is not
needed (the ability to access the individual bytes of objects is
needed in many cases, e.g. to create low level exact copies of
objects ) and it is unsafe (yes it is, low level stuff are unsafe
and it all depend on the programmer knowing what he does).
I am an Ada (not ADA) developer, and I use overlaid structures as
above in avionics software when necessary. However, Ada has better
constructs for "low-level exact copies". Ada's representation clauses
allow us to specify the bit pattern used for our low-level structures,
all the way down to endianness of numbers or absolute addresses.
It is up to oneself to learn whatever languages fits his
purposes. For example, a "safe" language is not an interest for me.
Then I am not interested entrusting my life to your software.
Someone who places much hopes on the language to protect him from
his mistakes, probably ADA is better than C++ on this.
Hear, hear!
There is no language that provides satisfies all people desires,
just because some desires are in contrast between them.


Agreed. Even in Ada, we sometimes use machine code insertions
("inline assembler") when we must.

--
Ludovic Brenta.
Jul 23 '05 #53
Ludovic Brenta wrote:
Ioannis Vranos writes:
The restriction that you imply you desire, limits flexibility.

Of course. That's what all these stories about shooting yourself in
the foot mean.

Once again, I have nothing against learning Ada, however personally
I like the most powerful languages. The next thing I am going to
learn after C++ (because I haven't learned it all yet), is probably
some form of assembly language.

Yes, assembly is the most powerful and flexible language. That's why
all compilers emit assembler.

For example I like that I can do:

[...]

in Ada, you would use an overlaid array of characters, like this:

with Ada.Strings.Unbounded;
with Ada.Text_IO;
procedure Unsafe_Proc is
type Some_Class is record
S : Ada.Strings.Unbounded.Unbounded_String;
end record;

Obj : aliased Some_Class :=
(S => Ada.Strings.Unbounded.To_Unbounded_String
("This is a text message"));

Obj_As_String : String (1 .. Obj'Size / System.Storage_Unit);
for Obj_As_String'Address use Obj'Address;
begin
for J in Obj_As_String'Range loop
Ada.Text_IO.Put_Line
(Integer'Image (Character'Pos (Obj_As_String (J))) &
" " &
Obj_As_String (J));
end loop;
end Unsafe_Proc;

May you provide the output of the code? Because I can not understand
much by itself. Can Ada

Then I am not interested entrusting my life to your software.

I wouldn't use low-level unsafe facilities for safety-critical
situations but types which have checks all over the place and RAII.

--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #54
Ludovic Brenta wrote:
in Ada, you would use an overlaid array of characters, like this:

with Ada.Strings.Unbounded;
with Ada.Text_IO;
procedure Unsafe_Proc is
type Some_Class is record
S : Ada.Strings.Unbounded.Unbounded_String;
end record;

Obj : aliased Some_Class :=
(S => Ada.Strings.Unbounded.To_Unbounded_String
("This is a text message"));

Obj_As_String : String (1 .. Obj'Size / System.Storage_Unit);
for Obj_As_String'Address use Obj'Address;
begin
for J in Obj_As_String'Range loop
Ada.Text_IO.Put_Line
(Integer'Image (Character'Pos (Obj_As_String (J))) &
" " &
Obj_As_String (J));
end loop;
end Unsafe_Proc;

May you provide the output of the code? Because I can not understand
much by itself. Can Ada display the decimal value of each byte that
consists an object of a user-defined type, along with the bit values of
these bytes?

Then I am not interested entrusting my life to your software.

I wouldn't use low-level unsafe facilities for safety-critical
situations but types which have checks all over the place and RAII.


--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #55
Ioannis Vranos <iv*@remove.this.grad.com> wrote in
news:1110059861.560004@athnrd02:

Once again, I have nothing against learning Ada, however personally I
like the most powerful languages. The next thing I am going to learn
after C++ (because I haven't learned it all yet), is probably some
form of assembly language.
For example I like that I can do:

#include <iostream>
#include <string>
#include <bitset>
#include <limits>

class SomeClass
{
std::string s;

public:
SomeClass()
{
s="This is a text message";
}
};
int main()
{
using namespace std;

SomeClass obj;

unsigned char *p= reinterpret_cast<unsigned char *>(&obj);

// Displays the individual bytes that obj
// consists of as unsigned chars.
for(unsigned i=0; i<sizeof(obj); ++i)
cout<<"character: "<<p[i]<<"\n";

cout<<"\n";
p= reinterpret_cast<unsigned char *>(&obj);
// Displays the decimal values of the
// individual bytes that obj consists of.
for(unsigned i=0; i<sizeof(obj); ++i)
cout<<static_cast<unsigned>(p[i])<<" ";

cout<<"\n\n";
// Displays the bits of each byte that consist
// this SomeClass object
p= reinterpret_cast<unsigned char *>(&obj);
for(unsigned i=0; i<sizeof(obj); ++i)
{
// A byte is not necessarily 8 bits
// numeric_limits<unsigned char>::digits retrieves the
number // of byte's bits, which *is* 8 usually.
bitset<numeric_limits<unsigned char>::digits> bits(p[i]);

for(unsigned j=0; j<bits.size(); ++j)
cout<<bits[j];

cout<<"\n";
}
}
C:\c>temp
character: ⁿ
character: =
character: >
character:

252 61 62 0

00111111
10111100
01111100
00000000

C:\c>

All this can be done in Ada.

How good is C++ at exactly representing bit fields?

Can C++ do this portably:

type Byte is mod 2**8;
type Sign_Flag is mod 2;

type Mouse_Status_Type is record
Left_Button_Pressed : Boolean;
Right_Button_Pressed : Boolean;
X_Movement_Sign : Sign_Flag;
Y_Movement_Sign : Sign_Flag;
X_Movement_Overflow : Boolean;
Y_Movement_Overflow : Boolean;
X_Movement_Magnitude : Byte;
Y_Movement_Magnitude : Byte;
end record;

for Mouse_Status_Type use record
Left_Button_Pressed at 0 range 0..0;
Right_button_Pressed at 0 range 1..1;
X_Movement_Sign at 0 range 4..4;
Y_Movement_Sign at 0 range 5..5;
X_Movement_Overflow at 0 range 6..6;
Y_Movement_Overflow at 0 range 7..7;
X_Movement_Magnitude at 1 range 0..7;
Y_Movement_Magnitude at 2 range 0..7;
end record;

The type Mouse_Status_Type defines a data
structure that occupies three bytes. The
first 6 fields of the record occupy a single
bit each, with bits 2 and 3 unused.

Furthermore, access to the individual fields of this record
are very direct, not requiring arcane bit masks.

foo : Mouse_Status_Type;
if foo.Left_Button_Pressed then
do_something;
end if;

I am sure that many ADA developers will say that this one is not
needed (the ability to access the individual bytes of objects is
needed in many cases, e.g. to create low level exact copies of objects
) and it is unsafe (yes it is, low level stuff are unsafe and it all
depend on the programmer knowing what he does).

On the contrary, Ada is frequently used for low level bit manipulation.
Ada was designed to be used in safety-critical hard real-time
embedded systems.

It is up to oneself to learn whatever languages fits his purposes. For
example, a "safe" language is not an interest for me.
We are all free to have our own interests. I do ask that you look at
the capabilities of a language before you decide they are not in your
interest. Ada does not prevent you from doing unsafe things. It
simply does not provide an unsafe behavior as its default.

Someone who places much hopes on the language to protect him from his
mistakes, probably ADA is better than C++ on this.
Programming is a human activity. All humans make mistakes. Some of those
mistakes are damned silly. Ada is designed to acknowledge that
programmers are human. Mistakes will be made. Ada attempts to identify
those mistakes as early in the development process as possible.
We all know that it is cheaper to fix mistakes early.


There is no language that provides satisfies all people desires, just
because some desires are in contrast between them.

And there is no perfect language. Ada is not meant to satisfy the
desires of all programmers. It is meant to support programming as
a human activity with the goal of producing high quality programs
very efficiently.

Jim Rogers

Jul 23 '05 #56
On Sat, 05 Mar 2005 23:59:08 +0100, Ludovic Brenta
<lu************@insalien.org> wrote:
What other mechanism would you suggest?


Termination of the program. Some might argue that they can't
tolerate such an event. But can such an environment tolerate a
faulty running program?

That's what an unhandled exception results in. In avionics, where we
have no operating system and no run-time system, exceptions cannot
propagate and thus always result in program termination. When testing
the program, we prove that no exception is ever raised.

There are certainly other strategies available. For instance, in an
"integrated modular avionics" architecture, an unhandled Ada exception in
a single partition could be forwarded to a global health monitoring
facility that may restart that partition, a set of partitions, or the
whole system - or do something else for error recovery. This implies that
exception propagation is a quite flexible capability, and can be embedded
in a system with even greater error handling flexibility in a comfortable
way.
Jul 23 '05 #57
Ioannis Vranos wrote:
Ioannis Vranos wrote:
In C++ you can be as safe, restricted and convenient as you want.

Including garbage collection.


Also, allowed by Ada95 language definition.
Jul 23 '05 #58
Ioannis Vranos wrote:
Ludovic Brenta wrote:
Generally speaking, the very fact that you feel an urge to distinguish
between "C++" and "modern C++" is an indication that C++ is a poor
language containing many unsafe features, some of which you obligingly
enumerated above. By contrast, there is no distinction between "Ada"
and "modern Ada". Ada is safe by design, from the ground up.
With Ada aside (I find no reason why one should not learn it), C++ is a
powerful and systems programming language, and power implies painful low
level details. However it also provides all major high level facilities,
and if you stick in high level programming it is very safe, while it
maintains the maximum space and run-time efficiency principle.


It does NOT provide multi-tasking... or fixed-point numbers...

In general, we cannot compare the two languages because they have
different design ideals.
We we _can_ compare them... but you are correct that we must take their
design considerations into account. Ada95 was design specifically to
support efficient, real-time safe environments (the OP of the original
thread question), C++ was designed to produce an object-orientated
extension to C.

C++ supports 4 paradigms. Each paradigm is supported well with maximum
run-time/space *efficiency*. At the same time it leaves no room for a
lower level language except of assembly.
Ada83 suffered from some pretty poor implementations, but Ada95 has
never had the same problems. My own experience is that Ada95 compilers
produce as efficient code as any other language with the exception of
assembler. Not scientific I know but...

On the other hand I do not know ADAs ideals (for example I do not think
it supports the generic programming paradigm - templates), but I suspect
they are to be an easy (restricted to easy parts), safe (not letting you
do low level operations), application development language, which is OK
for usual application development.


Oh dear! That's a shocker!!!! Ada had generics back in Ada83 - and _all_
Ada83 compiler supported it then! The debugger support back then was
pretty shabby, but hey, at least the compilers all supported it and in a
completely uniform fashion.

Cheers

-- Martin

Jul 23 '05 #59
Ludovico Brena wrote:
Most of Ada's syntax is inherited from Pascal.


I think Modula-3 was the prime inspiration but never having used it I
could be wrong! :-)
Jul 23 '05 #60
Peter Koch Larsen wrote:
It is not a question of prevention. C++ allows you to do some really
dangerous things - in my mind rightfully so. When you do program in C++ you
must "constrain yourself" and not use the dangeous stuff - unless you need
to do so, of course ;-)


And Ada lets you do all that but you have to be explicit that you are
doing it - I don't know of any other language that forces you to be
explicit that you are doing something dangerous.

Cheers

-- Martin
Jul 23 '05 #61
Jim Rogers wrote:
C:\c>temp
character: ⁿ
character: =
character: >
character:

252 61 62 0

00111111
10111100
01111100
00000000

C:\c>

All this can be done in Ada.

It would be great if we saw the code and its output.
How good is C++ at exactly representing bit fields?

Can C++ do this portably:

Some explanations with remarks in the code along with the output, would
make things easier to understand.
type Byte is mod 2**8;
type Sign_Flag is mod 2;

type Mouse_Status_Type is record
Left_Button_Pressed : Boolean;
Right_Button_Pressed : Boolean;
X_Movement_Sign : Sign_Flag;
Y_Movement_Sign : Sign_Flag;
X_Movement_Overflow : Boolean;
Y_Movement_Overflow : Boolean;
X_Movement_Magnitude : Byte;
Y_Movement_Magnitude : Byte;
end record;

for Mouse_Status_Type use record
Left_Button_Pressed at 0 range 0..0;
Right_button_Pressed at 0 range 1..1;
X_Movement_Sign at 0 range 4..4;
Y_Movement_Sign at 0 range 5..5;
X_Movement_Overflow at 0 range 6..6;
Y_Movement_Overflow at 0 range 7..7;
X_Movement_Magnitude at 1 range 0..7;
Y_Movement_Magnitude at 2 range 0..7;
end record;

The type Mouse_Status_Type defines a data
structure that occupies three bytes.

I guess the C++ equivalent is:

struct SomeStruct
{
unsigned Left_Button_Pressed: 1;
unsigned Right_button_Pressed: 1;
unsigned X_Movement_Sign: 1;
unsigned Y_Movement_Sign: 1;
unsigned X_Movement_Overflow: 1;
unsigned Y_Movement_Overflow: 1;
unsigned X_Movement_Magnitude: 8;
unsigned Y_Movement_Magnitude: 8;
};
It is interesting to see that ADA supports this.


The
first 6 fields of the record occupy a single
bit each, with bits 2 and 3 unused.

Furthermore, access to the individual fields of this record
are very direct, not requiring arcane bit masks.

foo : Mouse_Status_Type;
if foo.Left_Button_Pressed then
do_something;
end if;

The above in a simple C++ program:
#include <iostream>
int main()
{
struct SomeStruct
{
unsigned Left_Button_Pressed: 1;
unsigned Right_button_Pressed: 1;
unsigned X_Movement_Sign: 1;
unsigned Y_Movement_Sign: 1;
unsigned X_Movement_Overflow: 1;
unsigned Y_Movement_Overflow: 1;
unsigned X_Movement_Magnitude: 8;
unsigned Y_Movement_Magnitude: 8;
};

SomeStruct obj= {1, 0, true, false, 1, 16, 64};

if(obj.Left_Button_Pressed)
std::cout<<"It is pressed!\n";
}

C:\c>temp
It is pressed!

C:\c>

On the contrary, Ada is frequently used for low level bit manipulation.
Ada was designed to be used in safety-critical hard real-time
embedded systems.

It is interesting to hear that.

We are all free to have our own interests. I do ask that you look at
the capabilities of a language before you decide they are not in your
interest. Ada does not prevent you from doing unsafe things. It
simply does not provide an unsafe behavior as its default.

Perhaps I will check it sometime in the future.

Someone who places much hopes on the language to protect him from his
mistakes, probably ADA is better than C++ on this.

Programming is a human activity. All humans make mistakes. Some of those
mistakes are damned silly. Ada is designed to acknowledge that
programmers are human. Mistakes will be made. Ada attempts to identify
those mistakes as early in the development process as possible.
We all know that it is cheaper to fix mistakes early.

Yes, however I have the feeling that it does so by imposing several
restrictions that apart from protecting from possible misuses, also
prevent from flexible uses.

Again, this is just a feeling, I have not studied the language.

And there is no perfect language. Ada is not meant to satisfy the
desires of all programmers. It is meant to support programming as
a human activity with the goal of producing high quality programs
very efficiently.


OK.
--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #62
Martin Dowie wrote:
It does NOT provide multi-tasking... or fixed-point numbers...

C++ provides whatever the system it is used to provides. In Windows you
can create multithreading applications for example.

In general, we cannot compare the two languages because they have
different design ideals.

We we _can_ compare them... but you are correct that we must take their
design considerations into account. Ada95 was design specifically to
support efficient, real-time safe environments (the OP of the original
thread question), C++ was designed to produce an object-orientated
extension to C.

C++ is not only an OO language, but it is a multiparadigm one.
--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #63
In comp.realtime Martin Dowie <ma**********@btopenworld.com> wrote:
Ludovico Brena wrote:
Most of Ada's syntax is inherited from Pascal.


I think Modula-3 was the prime inspiration but never having used it I
could be wrong! :-)


Modula-3 *post*dated Ada by some years; it was designed in the late 80s
and unfortunately "missed the bus" - Ada was (at the time) very expensive,
C++ was (at the time) immature and unstandardised, and for a while I
hoped that Modula-3 would become the language of choice for large-scale
maintstream OOP/procedural programming.

Ada-83's ancestry is, as many have observed, mostly Pascal. (IIRC, three
of the four languages that got to the DoD's bake-off were Pascal-based;
a fourth was PL/1 based. Algol-68 was the other language identified as a
possible basis for the DoD's language, but no (directly) Algol-based
language made it that far.)

pete
--
pe**@fenelon.com "Send lawyers, guns and money...."
Jul 23 '05 #64
Ioannis Vranos wrote:
The above in a simple C++ program:
#include <iostream>
int main()
{
struct SomeStruct
{
unsigned Left_Button_Pressed: 1;
unsigned Right_button_Pressed: 1;
unsigned X_Movement_Sign: 1;
unsigned Y_Movement_Sign: 1;
unsigned X_Movement_Overflow: 1;
unsigned Y_Movement_Overflow: 1;
unsigned X_Movement_Magnitude: 8;
unsigned Y_Movement_Magnitude: 8;
};
SomeStruct obj= {1, 0, true, false, 1, 1, 16, 64};
if(obj.Left_Button_Pressed)
std::cout<<"It is pressed!\n";
}

C:\c>temp
It is pressed!

C:\c>

--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #65
Ioannis Vranos wrote:
Mark Lorenzen wrote:
You can do everything in Ada that you can in C and C++.
I suppose you mean in the application-programming domain. But I do not
think this is true in the systems programming domain, that is efficiency
under *severe* run-time and space constraints.


I'm afraid you don't know much about Ada and much of what you do know is
not correct. That was one of the specific problem domains Ada was
designed for -- hard real-time embedded systems.
Also I am not sure if ADA is suitable for library writing, or you will
have to switch to another language to do that.

I do not say this is bad, since the design ideals of ADA are different
from C++. In effect, we are comparing different things here.


No, you only think that's the case. I encourage you to learn more about
Ada. You might be very surprised.

Also, it's spelled "Ada", not ADA (which in the US usually means the
American Dental Association, or the Americans with Disabilities Act).
It's not an acronym. It was named after a woman, Ada Augusta Lovelace.
No one who knows anything about the language spells it ADA (unless
they're on an ancient machine that has no lowercase letters) anymore
than they spell "Pascal" as "PASCAL".

--Larry
Jul 23 '05 #66
[Reposted because follow-ups had redirected it]

Jim Rogers wrote:
C:\c>temp
character: ⁿ
character: =
character: >
character:

252 61 62 0

00111111
10111100
01111100
00000000

C:\c>

All this can be done in Ada.


It would be great if we saw the code and its output.
How good is C++ at exactly representing bit fields?

Can C++ do this portably:
Some explanations with remarks in the code along with the output, would
make things easier to understand.
type Byte is mod 2**8;
type Sign_Flag is mod 2;

type Mouse_Status_Type is record
Left_Button_Pressed : Boolean;
Right_Button_Pressed : Boolean;
X_Movement_Sign : Sign_Flag;
Y_Movement_Sign : Sign_Flag;
X_Movement_Overflow : Boolean;
Y_Movement_Overflow : Boolean;
X_Movement_Magnitude : Byte;
Y_Movement_Magnitude : Byte;
end record;

for Mouse_Status_Type use record
Left_Button_Pressed at 0 range 0..0;
Right_button_Pressed at 0 range 1..1;
X_Movement_Sign at 0 range 4..4;
Y_Movement_Sign at 0 range 5..5;
X_Movement_Overflow at 0 range 6..6;
Y_Movement_Overflow at 0 range 7..7;
X_Movement_Magnitude at 1 range 0..7;
Y_Movement_Magnitude at 2 range 0..7;
end record;

The type Mouse_Status_Type defines a data
structure that occupies three bytes.
I guess the C++ equivalent is:

struct SomeStruct
{
unsigned Left_Button_Pressed: 1;
unsigned Right_button_Pressed: 1;
unsigned X_Movement_Sign: 1;
unsigned Y_Movement_Sign: 1;
unsigned X_Movement_Overflow: 1;
unsigned Y_Movement_Overflow: 1;
unsigned X_Movement_Magnitude: 8;
unsigned Y_Movement_Magnitude: 8;
};
It is interesting to see that ADA supports this.


The
first 6 fields of the record occupy a single
bit each, with bits 2 and 3 unused.

Furthermore, access to the individual fields of this record
are very direct, not requiring arcane bit masks.

foo : Mouse_Status_Type;
if foo.Left_Button_Pressed then
do_something;
end if;
The above in a simple C++ program:
#include <iostream>
int main()
{
struct SomeStruct
{
unsigned Left_Button_Pressed: 1;
unsigned Right_button_Pressed: 1;
unsigned X_Movement_Sign: 1;
unsigned Y_Movement_Sign: 1;
unsigned X_Movement_Overflow: 1;
unsigned Y_Movement_Overflow: 1;
unsigned X_Movement_Magnitude: 8;
unsigned Y_Movement_Magnitude: 8;
};

SomeStruct obj= {1, 0, true, false, 1, 1, 16, 64};

if(obj.Left_Button_Pressed)
std::cout<<"It is pressed!\n";
}

C:\c>temp
It is pressed!

C:\c>

On the contrary, Ada is frequently used for low level bit manipulation.
Ada was designed to be used in safety-critical hard real-time embedded systems.

It is interesting to hear that.

We are all free to have our own interests. I do ask that you look at
the capabilities of a language before you decide they are not in your
interest. Ada does not prevent you from doing unsafe things. It simply does not provide an unsafe behavior as its default.

Perhaps I will check it sometime in the future.

Someone who places much hopes on the language to protect him from
his mistakes, probably ADA is better than C++ on this.
Programming is a human activity. All humans make mistakes. Some of those
mistakes are damned silly. Ada is designed to acknowledge that
programmers are human. Mistakes will be made. Ada attempts to identify
those mistakes as early in the development process as possible.
We all know that it is cheaper to fix mistakes early.
Yes, however I have the feeling that it does so by imposing several
restrictions that apart from protecting from possible misuses, also
prevent from flexible uses.

Again, this is just a feeling, I have not studied the language.

And there is no perfect language. Ada is not meant to satisfy the
desires of all programmers. It is meant to support programming as
a human activity with the goal of producing high quality programs
very efficiently.

OK.
--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #67
Larry Elmore wrote:
I'm afraid you don't know much about Ada and much of what you do know is
not correct. That was one of the specific problem domains Ada was
designed for -- hard real-time embedded systems.

Yes, after some things I have read in the thread, Ada is upper in my
interest scale.

I did not know that it was designed for low level stuff.

--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #68
Martin Dowie wrote:
Ludovico Brena wrote:
Most of Ada's syntax is inherited from Pascal.

I think Modula-3 was the prime inspiration but never having used it I
could be wrong! :-)


Definitely not Modula 3, which dates from the latter half of the 1980s.
I remember the introduction to the original book published about it
mentioning how they learned from errors made in the designs of Modula 2
and Ada83. I've never used it, but I remember thinking it did have some
good ideas (although they kept the damnable 'begin .. end' keywords and
a couple of other things that I no longer remember instead of using
Ada's much better syntax).

--Larry
Jul 23 '05 #69
On Sun, 6 Mar 2005 01:03:30 +0000 (UTC), Martin Dowie
<ma**********@btopenworld.com> declaimed the following in comp.lang.ada:
Ludovico Brena wrote:
Most of Ada's syntax is inherited from Pascal.
I think Modula-3 was the prime inspiration but never having used it I
could be wrong! :-)


Considering that the Ada effort started in the mid-70s, I don't
even think Modula-2 was available. See
http://www.cs.fit.edu/~ryan/ada/ada-hist.html for dates.

As I recall from my studies (the choice Green to become Ada
occurred in time for me to use it in a language report for a college
class) the four teams that competed in the proposal all chose Pascal as
their starting point.

-- ================================================== ============ <
wl*****@ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG <
wu******@dm.net | Bestiaria Support Staff <
================================================== ============ <
Home Page: <http://www.dm.net/~wulfraed/> <
Overflow Page: <http://wlfraed.home.netcom.com/> <

Jul 23 '05 #70
Ioannis Vranos <iv*@remove.this.grad.com> wrote in news:1110072229.85604
@athnrd02:
Jim Rogers wrote:
C:\c>temp
character: ⁿ
character: =
character: >
character:

252 61 62 0

00111111
10111100
01111100
00000000

C:\c>


All this can be done in Ada.

It would be great if we saw the code and its output.


Ok. That is certainly a fair requirement.

with Ada.Text_Io;
with Ada.Integer_Text_Io;
with System;

procedure String_Bits is
S : String := "This is a text message";
L : Natural := S'Size;
type Bits_Array is array (1..L) of Boolean;
pragma Pack (Bits_Array);
Bits : Bits_Array;
for Bits'Address use S'Address;
begin
-- Display the bits of each character
for I in Bits'range loop
Ada.Integer_Text_Io.Put(Item => Boolean'Pos(Bits(I)), Width => 1);
if I mod System.Storage_Unit = 0 then
Ada.Text_Io.New_Line;
end if;
end loop;
end String_Bits;

The output is:
00101010
00010110
10010110
11001110
00000100
10010110
11001110
00000100
10000110
00000100
00101110
10100110
00011110
00101110
00000100
10110110
10100110
11001110
11001110
10000110
11100110
10100110

The program declares a string S initialized to "This is a text message".
It then declares an array type named Bits_Array. That array type is an
array of Boolean, with the number of elements equal to the number of
bits in used by S. The variable L is set to equal the value returned
by the Size attribute of the String S. Ada reports size as the number
of bits, not the number of bytes.

A packed array of boolean allocates one storage element to each bit.
Therefore, the statement
pragma Pack(Bits_Array);
causes all instances of Bits_Array to be a packed array.
The variable Bits is declared to be of the type Bits_Array.
The next statement forces Bits to overlay S. Both variables
are the same size and start at the same address.

The body of the procedure simply iterates through all the bits in
the Bits variable and prints the numeric value of each bit.
A new line is output whenever the loop control variable mod
System.Storage_Unit evaluates to 0. System.Storage_Unit is
provided by Ada so that the program will properly represent
each storage unit (sometimes called a byte) no matter what the
size of that unit is.

As you can clearly see, Ada can represent the bits of a
variable with very little difficulty.

Ada does not store a null at the end of a string. This is
why there is no indication of a null value for the last byte.

Jim Rogers

Jul 23 '05 #71
Ioannis Vranos <iv*@remove.this.grad.com> wrote in
news:1110072660.15684@athnrd02:
Martin Dowie wrote:
It does NOT provide multi-tasking... or fixed-point numbers...

C++ provides whatever the system it is used to provides. In Windows
you can create multithreading applications for example.


Of course it can, by calling C libraries such as pThreads.

Concurrency has been a native part of Ada since the 1983 standard.


In general, we cannot compare the two languages because they have
different design ideals.

We we _can_ compare them... but you are correct that we must take
their design considerations into account. Ada95 was design
specifically to support efficient, real-time safe environments (the
OP of the original thread question), C++ was designed to produce an
object-orientated extension to C.

C++ is not only an OO language, but it is a multiparadigm one.

I agree. One of the original goals of C++ was to produce a language
that extends C into the OO paradigm without loosing any of the
inherited C capabilities. In 1996 C++ standardized generic programming
as another paradigm.

Ada is also a multi-paradigm language. In fact, it can be used in all
the paradigms familiar to C++.

Jim Rogers

Jul 23 '05 #72
"Ioannis Vranos" <iv*@remove.this.grad.com> wrote in message
news:1110055473.613245@athnrd02...
You can also express constraints in templates. An important thing is this.
Are Ada's generics run-time or compile time?
Compile time with every Ada compiler I've used.
It looks like they are run-time, and in C++ you can do all the above.
Actually Ada's compilers are probably written in C++.


GNAT is written in Ada.

Jul 23 '05 #73
"Pascal Obry" <pa****@obry.org> wrote in message
news:ub***********@obry.org...
At least GNAT (GNU/Ada) is written in Ada and DEC Ada was written in Ada
IIRC.


Half right. GNAT is written in Ada, DEC Ada was written in Bliss.
Jul 23 '05 #74
Jim Rogers wrote:
Of course it can, by calling C libraries such as pThreads.

Actually I am using .NET facilities (posted an example in another
message in the thread).

I agree. One of the original goals of C++ was to produce a language
that extends C into the OO paradigm without loosing any of the
inherited C capabilities. In 1996 C++ standardized generic programming
as another paradigm.

Ada is also a multi-paradigm language. In fact, it can be used in all
the paradigms familiar to C++.


OK.

--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #75
Jim Rogers wrote:
The program declares a string S initialized to "This is a text message".
It then declares an array type named Bits_Array. That array type is an
array of Boolean, with the number of elements equal to the number of
bits in used by S. The variable L is set to equal the value returned
by the Size attribute of the String S. Ada reports size as the number
of bits, not the number of bytes.

A packed array of boolean allocates one storage element to each bit.
Therefore, the statement
pragma Pack(Bits_Array);
causes all instances of Bits_Array to be a packed array.
The variable Bits is declared to be of the type Bits_Array.
The next statement forces Bits to overlay S. Both variables
are the same size and start at the same address.

Does this mean that Boolean always occupies 1 bit and has no padding bits?

The body of the procedure simply iterates through all the bits in
the Bits variable and prints the numeric value of each bit.
A new line is output whenever the loop control variable mod
System.Storage_Unit evaluates to 0. System.Storage_Unit is
provided by Ada so that the program will properly represent
each storage unit (sometimes called a byte) no matter what the
size of that unit is.

As you can clearly see, Ada can represent the bits of a
variable with very little difficulty.

Ada does not store a null at the end of a string. This is
why there is no indication of a null value for the last byte.

While this is an interesting thing, I have the feeling that this
approach does not print all bits, including padding bits, of a
*user-defined type*.
In C++ you can read (and thus copy, print or anything) every byte of any
type.

In the example you provided, I have the feeling that you allocated a
character array (the string) and then treated is a boolean array
(somewhat a hacking attempt to imitate the behaviour).
However what happens in the case of a user defined type (I suppose Ada
supports OO programming) or a record. Can you print the byte
implementation of such an object?
Also for a built in type, say a floating point, can you print its
implementation bytes too (including padding bits)?
Consider this:

#include <iostream>
#include <bitset>
#include <limits>

int main()
{
using namespace std;

double obj= 0.45435;

unsigned char *p= reinterpret_cast<unsigned char *>(&obj);
p= reinterpret_cast<unsigned char *>(&obj);
// Displays the decimal values of the
// individual bytes that obj consists of.
for(unsigned i=0; i<sizeof(obj); ++i)
cout<<static_cast<unsigned>(p[i])<<" ";

cout<<"\n\n";
// Displays the bits of each byte that consist
// this SomeClass object
p= reinterpret_cast<unsigned char *>(&obj);
for(unsigned i=0; i<sizeof(obj); ++i)
{
// A byte is not necessarily 8 bits
// numeric_limits<unsigned char>::digits retrieves the number
// of byte's bits, which *is* 8 usually.
bitset<numeric_limits<unsigned char>::digits> bits(p[i]);

for(unsigned j=0; j<bits.size(); ++j)
cout<<bits[j];

cout<<"\n";
}
}
C:\c>temp
163 1 188 5 18 20 221 63

11000101
10000000
00111101
10100000
01001000
00101000
10111011
11111100

C:\c>

--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #76
In article <Fs*********************@news000.worldonline.dk> , "Peter Koch Larsen" <pk*****@mailme.dk> writes:
It's kind of like driving. You can get into a lot of trouble if you do not
follow the traffic laws (you just have to obey the physicla ones ;-), but so
long as you do driving is a fairly safe practice.


Although I attempt to drive safely, I also rely on seat belts and air bags.
Jul 23 '05 #77
In article <d0**********@titan.btinternet.com>, Martin Dowie <ma**********@btopenworld.com> writes:
Oh dear! That's a shocker!!!! Ada had generics back in Ada83 - and _all_
Ada83 compiler supported it then! The debugger support back then was
pretty shabby,


Speak for your own compiler, VAX Ada has (and had) excellent debugger
support.
Jul 23 '05 #78
Ioannis Vranos <iv*@remove.this.grad.com> wrote in
news:1110082147.830198@athnrd02:
Jim Rogers wrote:
The program declares a string S initialized to "This is a text
message". It then declares an array type named Bits_Array. That array
type is an array of Boolean, with the number of elements equal to the
number of bits in used by S. The variable L is set to equal the value
returned by the Size attribute of the String S. Ada reports size as
the number of bits, not the number of bytes.

A packed array of boolean allocates one storage element to each bit.
Therefore, the statement
pragma Pack(Bits_Array);
causes all instances of Bits_Array to be a packed array.
The variable Bits is declared to be of the type Bits_Array.
The next statement forces Bits to overlay S. Both variables
are the same size and start at the same address.

Does this mean that Boolean always occupies 1 bit and has no padding
bits?


No. A boolean usually occupies a byte. A packed array of boolean
is compressed so that each boolean element of the array occupies only
one bit.
The body of the procedure simply iterates through all the bits in
the Bits variable and prints the numeric value of each bit.
A new line is output whenever the loop control variable mod
System.Storage_Unit evaluates to 0. System.Storage_Unit is
provided by Ada so that the program will properly represent
each storage unit (sometimes called a byte) no matter what the
size of that unit is.

As you can clearly see, Ada can represent the bits of a
variable with very little difficulty.

Ada does not store a null at the end of a string. This is
why there is no indication of a null value for the last byte.

While this is an interesting thing, I have the feeling that this
approach does not print all bits, including padding bits, of a
*user-defined type*.


The same approach will work for any type, including any padding
bits. The Size attribute reports the total number of bits used
by an object.


In C++ you can read (and thus copy, print or anything) every byte of
any type.

In the example you provided, I have the feeling that you allocated a
character array (the string) and then treated is a boolean array
(somewhat a hacking attempt to imitate the behaviour).
I created a string, which is an array of character in Ada.
I also created an packed array of boolean with exactly the same
size as the array of character. I then specified that both
variables will occupy the same space; one overlays the other.


However what happens in the case of a user defined type (I suppose Ada
supports OO programming) or a record. Can you print the byte
implementation of such an object?
Also for a built in type, say a floating point, can you print its
implementation bytes too (including padding bits)?


The following example starts with the creation of a generic package
for printing the byte and bit output of an object of any type.
The program then instantiates that package for a user-defined
type and for a long_float, which is equivalent to a C++ double.

generic
type Target_Type is private;
Target_Size : Natural;
package Bit_Utils is
procedure Show_Bits(Item : Target_Type);
end Bit_Utils;
with Ada.Text_Io;
with Ada.Integer_Text_Io;
with System;
package body Bit_Utils is
type Bits_Array is array(Positive range <>) of Boolean;
pragma Pack(Bits_Array);

type Byte is mod 2**8;
type Byte_Array is array(Positive range <>) of Byte;
package Mod_Io is new Ada.Text_IO.Modular_IO(Byte);

procedure Show_Bits(Item : Target_Type) is
Bit_View : Bits_Array(1..Target_Size);
for Bit_View'Address use Item'Address;
Byte_View : Byte_Array(1..Target_Size / Byte'Size);
For Byte_View'Address use Item'Address;
begin
for I in Byte_View'range loop
Mod_Io.Put(Item => Byte_View(I), Width => 4);
end loop;
Ada.Text_IO.New_Line(2);
for I in Bit_View'range loop
Ada.Integer_Text_Io.Put(Item => Boolean'Pos(Bit_View(I)),
Width => 1);
if I mod System.Storage_Unit = 0 then
Ada.Text_IO.New_Line;
end if;
end loop;
end Show_Bits;
end Bit_Utils;

with Bit_Utils;
with Ada.Text_IO;

procedure Bit_Output is
type My_Type is record
Name : String(1..4);
Age : Positive;
Weight : Long_Float;
end record;
package My_Bits is new Bit_Utils(My_Type, My_Type'Size);
package Flt_Bits is new Bit_Utils(Long_Float, Long_Float'Size);

Mt : My_Type := ("Jim ", 55, 0.45435);
D : Long_Float := 0.45435;
begin
Ada.Text_Io.Put_Line("Output of My_Type");
My_Bits.Show_Bits(Mt);
Ada.Text_Io.Put_Line("Output of Long_Float");
Flt_Bits.Show_Bits(D);
end Bit_Output;
The output of this program is:

Output of My_Type
74 105 109 32 55 0 0 0 163 1 188 5 18 20 221 63

01010010
10010110
10110110
00000100
11101100
00000000
00000000
00000000
11000101
10000000
00111101
10100000
01001000
00101000
10111011
11111100
Output of Long_Float
163 1 188 5 18 20 221 63

11000101
10000000
00111101
10100000
01001000
00101000
10111011
11111100
Ada provides capabilities similar to C++ in the area of copying
and viewing data.

Jim Rogers

Jul 23 '05 #79
On Sat, 5 Mar 2005 23:44:56 +0100, Peter Koch Larsen wrote:
"Ludovic Brenta" <lu************@insalien.org> skrev i en meddelelse
news:87************@insalien.org...

This is the crux of the problem. Assuming that the programmer "knows
the rules", "makes no mistakes" or "can be trusted" is a recipe for
disaster. One of the principles in Ada's rationale is to make
everything explicit, rather than implicit.


Do you also require parenthesis when mixing addition and multiplication? I
do not like that degree of nannying - a matter of taste, surely.


That's the Ada's way. The following is also illegal without brackets:

+ - 2
A**+2

Though they might look unambiguous, no sensible man would write something
like above.

As for addition and multiplication. The association rules of */+ differs
from ones of and/or:

x + (y * z) is not equivalent to (x + y) * (x + z)

So there is a canonic representation of algebraic expressions with */+. For
and/or the picture is different:

x and (y or z) = (x and y) or (x and z)
(x and y) or z = (x or z) and (y or z)

There is no dedicated representation: a normal disjunctive form is as good
as a normal conjunctive one.
type Weight is digits 8 range 0.0 .. 900.0; -- 8 decimal digits of
precision
type Length is digits 8 range 0.0 .. 1000.0;

Now these types are incompatible. If you want to mix them, you need
to define the semantics and provide the appropriate operators:

type Weight_Length is digits 8 range 0.0 .. 900_000.0;

function "*" (Left : in Weight; Right : in Length) return Weight_Length;

Since you don't provide "+", there is no way to add a weight to a
length.

For a more general discussion of physical quantities in Ada, see:

http://home.t-online.de/home/Christ-.../Universe.html


I believe I will prefer the C++ solution - a template that copes with all
this stuff.


Try to write a unit calculator using templates ...

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
Jul 23 '05 #80
Ioannis Vranos wrote:
Ludovic Brenta wrote:
Generally speaking, the very fact that you feel an urge to distinguish
between "C++" and "modern C++" is an indication that C++ is a poor
language containing many unsafe features, some of which you obligingly
enumerated above. By contrast, there is no distinction between "Ada"
and "modern Ada". Ada is safe by design, from the ground up.

With Ada aside (I find no reason why one should not learn it), C++ is a
powerful and systems programming language, and power implies painful low
level details.


But Ada is used for system programming language as well. Only it is not
painfull. Most C/C++ programmers think that a language suitable for system
programming must be painfull - but this is not true.

Well, there is a drawback: you have to type more. But then: once you typed
it in it's easer to read - and most programms are read more then written.
However it also provides all major high level facilities,
and if you stick in high level programming it is very safe, while it
maintains the maximum space and run-time efficiency principle.
The real difference is that Ada puts emphasis on "save" while C++ puts
emphasis on "fast". C++ only becomes save by use of the STL.

And with the speed of the computers today "save" is better. I remember well
the time when Blaster/32 infected my computer faster then I could download
the fix (download the fix with Linux in the end - but that's another
story).
In general, we cannot compare the two languages because they have
different design ideals.
That is indeed true. But the differences are not system vs application -
both languages draw even here. Its save vs. fast, readabiltiy vs.
writeablity and explicid vs implicid.

Of corse, having stessed the save vs. fast point: Most Ada compiler allow
you to switch off the savety net with a compiler option.
C++ supports 4 paradigms. Each paradigm is supported well with maximum
run-time/space *efficiency*.
Ada supports the same 4 paradigms and concurrent programming on top.
At the same time it leaves no room for a
lower level language except of assembly.
True. But C/C++ havn't got a monopoly/patent on that feature.
On the other hand I do not know ADAs ideals (for example I do not think
it supports the generic programming paradigm - templates), but I suspect
Actualy Ada has templates since it's 1983 release. I don't think C++ had
templates at the time.
they are to be an easy (restricted to easy parts),
True Ada is easy - but not restricted. You think one excludes the other -
but that isn't true.
safe (not letting you
do low level operations),
Ada can do more low level stuff then C++ - or have you ever seen 24 bit
integer types in C++.
application development language, which is OK
for usual application development.


As I said, here you as mistaken. While Ada is indeed well suited for high
level application development is is mostly used for low level embedded
programming. Usualy in planes, railways, spacecraft and weapons.

I usualy read - at least - the wiki article before I say anything about a
programming language:

http://en.wikipedia.org/wiki/Ada_programming_language

With Regards

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

Jul 23 '05 #81
Ioannis Vranos wrote:
Martin Krischik wrote:
Well that's easy:

unsigned int X = -1;

char Y [10];
Y [10] = "X";

Or bit more subtle:

unsigned int X Day_Of_Month = 32;
Day_Of_Month does not compile.
Shure - the X is to much - a cut/copy/paste mistake.
You can make the Day_Of_Month an enum:
Day_Of_Month - not Day_Of_Week ;-)
Bottom line is in C++ you can be as safe and as high level you like.
Just pick the suitable libraries or frameworks.


I know. But the *default* is unsave - you have to explicitly *activate*
save. While in Ada it's the other way round (yes you can deactivate save in
Ada if you need to).

Martin

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

Jul 23 '05 #82
Martin Krischik wrote:
But Ada is used for system programming language as well. Only it is not
painfull. Most C/C++ programmers think that a language suitable for system
programming must be painfull - but this is not true.

Well, there is a drawback: you have to type more. But then: once you typed
it in it's easer to read - and most programms are read more then written.

The real difference is that Ada puts emphasis on "save" while C++ puts
emphasis on "fast". C++ only becomes save by use of the STL.

And with the speed of the computers today "save" is better. I remember well
the time when Blaster/32 infected my computer faster then I could download
the fix (download the fix with Linux in the end - but that's another
story).

That is indeed true. But the differences are not system vs application -
both languages draw even here. Its save vs. fast, readabiltiy vs.
writeablity and explicid vs implicid.

Of corse, having stessed the save vs. fast point: Most Ada compiler allow
you to switch off the savety net with a compiler option.

Ada supports the same 4 paradigms and concurrent programming on top.

True. But C/C++ havn't got a monopoly/patent on that feature.

Actualy Ada has templates since it's 1983 release. I don't think C++ had
templates at the time.

True Ada is easy - but not restricted. You think one excludes the other -
but that isn't true.

Ada can do more low level stuff then C++ - or have you ever seen 24 bit
integer types in C++.

As I said, here you as mistaken. While Ada is indeed well suited for high
level application development is is mostly used for low level embedded
programming. Usualy in planes, railways, spacecraft and weapons.

I usualy read - at least - the wiki article before I say anything about a
programming language:

http://en.wikipedia.org/wiki/Ada_programming_language

Certainly after the thread discussion, ADA has ascended a lot in my
interest scale (I always try to be reasonable).
In that Wiki link I saw it is covering a subset of the procedural
paradigm and recently also got support for OO. Also it supports generics.

The one remaining, does it support namespaces? :-) What subset of the
procedural paradigm it does not support?
Also I saw that under severe constraints the run-time safety of the
language is better to be switched off.
I do not know much on the language, but can one define general-purpose
containers with Ada's generics that do range checking and throw an
exception when there is an attempt to access outside the boundaries of
the container, even if the aforementioned run-time safety is switched off?

--
Ioannis Vranos

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

"Larry Kilgallen" <Ki*******@SpamCop.net> skrev i en meddelelse
news:CU**********@eisner.encompasserve.org...
In article <Fs*********************@news000.worldonline.dk> , "Peter Koch
Larsen" <pk*****@mailme.dk> writes:
It's kind of like driving. You can get into a lot of trouble if you do
not
follow the traffic laws (you just have to obey the physicla ones ;-), but
so
long as you do driving is a fairly safe practice.


Although I attempt to drive safely, I also rely on seat belts and air
bags.


I hope we all do. What i meant to say was that using a seat belt isn't an
excuse to drive on the wrong side of the road.

/Peter
Jul 23 '05 #84
On Sun, 6 Mar 2005 10:22:48 +0100, Peter Koch Larsen wrote:
"Larry Kilgallen" <Ki*******@SpamCop.net> skrev i en meddelelse
news:CU**********@eisner.encompasserve.org...
In article <Fs*********************@news000.worldonline.dk> , "Peter Koch
Larsen" <pk*****@mailme.dk> writes:
It's kind of like driving. You can get into a lot of trouble if you do
not
follow the traffic laws (you just have to obey the physicla ones ;-), but
so
long as you do driving is a fairly safe practice.


Although I attempt to drive safely, I also rely on seat belts and air
bags.


I hope we all do. What i meant to say was that using a seat belt isn't an
excuse to drive on the wrong side of the road.


Yes, in Britain (:-)) Ada compiler will ask you to apply
Unchecked_Conversion to the road sides, before you will be able to run the
engine ...

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
Jul 23 '05 #85
Peter Koch Larsen wrote:

"Larry Kilgallen" <Ki*******@SpamCop.net> skrev i en meddelelse
news:Q5**********@eisner.encompasserve.org...
In article <1110053977.478846@athnrd02>, Ioannis Vranos
<iv*@remove.this.grad.com> writes:
Mark Lorenzen wrote:

You can do everything in Ada that you can in C and C++.
I suppose you mean in the application-programming domain. But I do not
think this is true in the systems programming domain, that is efficiency
under *severe* run-time and space constraints.


And what guesswork makes you think there would be efficiency problems
with Ada ?
Also I am not sure if ADA is suitable for library writing, or you will
have to switch to another language to do that.


Huh ?

Again, what guesswork makes you suggest that ?

It is even possible in Ada to make the calling convention be the
unsafe C-style interface (null terminated strings, etc.). But for
better safety in all the languages that might call the library,
it is better to avoid those C conventions.


It is also possible to use zero-terminated strings in C++, but every
knowledgeable person will advice that you use std::string. So what is the
difference here?


The defaults (that is the i.E. the constant expression "Hello Word!"):

Default in Ada are save strings - zero terminated via extenral library
(Interfaces.C.Strings).

Default in C++ is zero terminated, save strings via external library
(std::string).

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

Jul 23 '05 #86
Peter Koch Larsen wrote:
It is not a question of prevention. C++ allows you to do some really
dangerous things - in my mind rightfully so.
So does Ada. In fact Ada.Unchecked_Convertion will convert variables no C++
compiler will ever dare to convert. Yes I know, you can allways use a
reinterpret_cast <void*> in the middle.

http://en.wikibooks.org/wiki/Program...ked_Conversion
When you do program in C++
you must "constrain yourself" and not use the dangeous stuff - unless you
need to do so, of course ;-)
In Ada you don't need to constrain yourself. I found that a very freeing
exprience - after 10+ years of C/C++ programming. And I can still use the
dangeous stuff when I need to.

And see the difference in our sentences here:

You: contrain, not use, unless - all so negative terms.
Me: don't contrain, still use, when - so more positive terms.
It's kind of like driving. You can get into a lot of trouble if you do not
follow the traffic laws (you just have to obey the physicla ones ;-), but
so long as you do driving is a fairly safe practice.


Have you ever seen the traffic in a country where a 10 $ or 10 note will
make any traffic policemen put is pen back into its pocket.

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

Jul 23 '05 #87
Ioannis Vranos <iv*@remove.this.grad.com> writes:
The one remaining, does it support namespaces? :-) What subset of the
procedural paradigm it does not support?
Yes, of course.
I do not know much on the language, but can one define general-purpose
containers with Ada's generics that do range checking and throw an
exception when there is an attempt to access outside the boundaries of
the container, even if the aforementioned run-time safety is switched
off?


Yes, but there's no point, as turning off the automatic boundary
checks and then do manual boundary checks instead doesn't gain you
anything except pain. (In fact, the automatic boundary checks can be
more efficent since compilers might optimize away checks that aren't
needed.)

--
Leif Roar Moldskred
Jul 23 '05 #88
<verffentlicht & per Mail versendet>

Paul E. Bennett wrote:
Ludovic Brenta wrote:
* when the compiler cannot check some code statically, it inserts
run-time checks which are guaranteed to catch all errors by raising
exceptions. In C++ you must code these checks by hand, and of
course at some point you'll forget one crucial check which will cost
you days in debugging.


I think the fallacy of that statement has been proven already (in a very
expensive way).


You mean the case where some managers decided to use some software written
for one pice of hardware on another - incompatible - pice of hardware -
without retesting?

In my book that was a management bug - If the managers had ordered to run
the testsuite only once the problem would have shown. The hardware was so
incompatible it would have failed all the time.

Last not least: Runtime check where disabled for that incident. So if
anything: this incident speak in favor of runtime checks.

Read up your facts: http://en.wikipedia.org/wiki/Ariane_5_Flight_501

Martin

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

Jul 23 '05 #89
Ioannis Vranos wrote:
Martin Krischik wrote:
I usualy read - at least - the wiki article before I say anything about a
programming language:

http://en.wikipedia.org/wiki/Ada_programming_language

Certainly after the thread discussion, ADA has ascended a lot in my
interest scale (I always try to be reasonable).
If your interest has been raised there is a larger Ada article on Wikibooks:

http://en.wikibooks.org/wiki/Programming:Ada
In that Wiki link I saw it is covering a subset of the procedural
paradigm and recently also got support for OO. Also it supports generics. The one remaining, does it support namespaces? :-) What subset of the
procedural paradigm it does not support?
Yes, they are called packages and have been in Ada since 1983.

http://en.wikibooks.org/wiki/Programming:Ada:Packages

However they are move powerfull. For example generics are based on packages,
a bit like:

template <....> namespace Generic {};
Also I saw that under severe constraints the run-time safety of the
language is better to be switched off.
Which I never do. With activated optimizer the performance loss is so low
there is almost no point in switching run-time check of.
I do not know much on the language, but can one define general-purpose
containers with Ada's generics that do range checking and throw an
exception when there is an attempt to access outside the boundaries of
the container, even if the aforementioned run-time safety is switched off?


Shure, there are several container libs around, all doing that.

http://en.wikibooks.org/wiki/Program...ries:Container

I have to confess that only the new Ada 2005 will have containers as a build
in features. With the current Ada 95 you have to use external libraries.

Martin

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

Jul 23 '05 #90
Adrien Plisson wrote:
Ludovic Brenta wrote:
The one thing that C++ supports that Ada doesn't is multiple
inheritance. This feature was left out as unsafe. Interface
inheritance la Java is being added in Ada 2005.
there is also one other thing i can think of: template specialization. this is an interresting construct, used a lot in C++, which gives the
ability to write "traits". there may be a way to do it in Ada but i'm
not aware of it (if there is, please tell me).


Yes traits would be tricky - but not impossible. Ada allows for both
procedures and packages as generic formal parameter:

http://www.adaic.org/standards/95lrm/html/RM-12-6.html
http://www.adaic.org/standards/95lrm/html/RM-12-7.html

However there are two important differences here which would make traits a
typing feast in Ada:

1) Ada generics work on procedures and packages but not classes. A bit like
template <...> namespace X {};

2) Ada genenrics only instanciate explicitly. Well it's a hole namespace
with all classes, prodedures, types and data after all.

But as I said, not impossible. I have a regex generic which can be
instanciated for character and wide character strings and basicly any other
descreed type you want to run regular expressing over.

With Regards

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

Jul 23 '05 #91
Ioannis Vranos wrote:
Martin Dowie wrote:
It does NOT provide multi-tasking... or fixed-point numbers...
C++ provides whatever the system it is used to provides.
If it is not in the ISO/IEC 14882 than it is not provided by the language
but only plugged on externaly.
In Windows you
can create multithreading applications for example.
I have a multi-tastking Ada application which runs on OS/2, Windows XP and
Linux. Can you do that in C++ without the use of "#if". Here is the problem
of plugged on solution: they are not compatible between operating system
and compiler vendors.

And even if you find a lib who can all three - I just ask a Mac-OS and
Solaris user on comp.lang.ada to run a test - The Ada multithreading is
part of the ISO/IEC 8652 standart - you recompile it on the next system and
it runs.
C++ is not only an OO language, but it is a multiparadigm one.


So is Ada only with a few more paradigms build in and not plugged onto by
external libraries.

Again "build in" means defined by "ISO/IEC" - everything else does not count
when comparing languages.

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

Jul 23 '05 #92
Martin Krischik wrote:
<verffentlicht & per Mail versendet>

Paul E. Bennett wrote:
Ludovic Brenta wrote:
* when the compiler cannot check some code statically, it inserts
run-time checks which are guaranteed to catch all errors by raising
exceptions. In C++ you must code these checks by hand, and of
course at some point you'll forget one crucial check which will cost
you days in debugging.


I think the fallacy of that statement has been proven already (in a very
expensive way).


You mean the case where some managers decided to use some software written
for one pice of hardware on another - incompatible - pice of hardware -
without retesting?

In my book that was a management bug - If the managers had ordered to run
the testsuite only once the problem would have shown. The hardware was so
incompatible it would have failed all the time.

Last not least: Runtime check where disabled for that incident. So if
anything: this incident speak in favor of runtime checks.

Read up your facts: http://en.wikipedia.org/wiki/Ariane_5_Flight_501


Yes, I have read that and the full report. However, I think my comment
still stands. You stated "when the compiler cannot check some code
statically, it inserts run-time checks which are guaranteed to catch all
errors by raising exceptions". The code had to be compiled, for the new
hardware, to be installed in the guidance system and hence should have had
the run-time checks in place if static checking could not be done. You have
admitted in your response that these checks were not active (by management
decision) so the Ada compiler was circumvented and prohibited from adding
these checks.

Considering that the proposition in this thread has been "Ada protects you
from making silly mistakes" I consider that your take is counter to the
evidence. I still maintain that language is immaterial to the safety of the
system, relying on decent rigourously applied development processes,
reviews and testing. Therefore, I tend to look at the development processes
and their "real" CMM rating. I guess the Ariane team went down a few
notches on that project.

--
************************************************** ******************
Paul E. Bennett ....................<email://pe*@amleth.demon.co.uk>
Forth based HIDECS Consultancy .....<http://www.amleth.demon.co.uk/>
Mob: +44 (0)7811-639972
Tel: +44 (0)1235-811095
Going Forth Safely ....EBA. http://www.electric-boat-association.org.uk/
************************************************** ******************
Jul 23 '05 #93
Larry Kilgallen wrote:
In article <Fs*********************@news000.worldonline.dk> , "Peter Koch
Larsen" <pk*****@mailme.dk> writes:
It's kind of like driving. You can get into a lot of trouble if you do
not follow the traffic laws (you just have to obey the physicla ones ;-),
but so long as you do driving is a fairly safe practice.


Although I attempt to drive safely, I also rely on seat belts and air
bags.


It has often been commented that a sharp spike protruding from the centre
of the steering wheel will elicit more safe driving than seatbelts or
airbags. Getting used to having a safety net will tend to lead to the less
cautious approach.

--
************************************************** ******************
Paul E. Bennett ....................<email://pe*@amleth.demon.co.uk>
Forth based HIDECS Consultancy .....<http://www.amleth.demon.co.uk/>
Mob: +44 (0)7811-639972
Tel: +44 (0)1235-811095
Going Forth Safely ....EBA. http://www.electric-boat-association.org.uk/
************************************************** ******************
Jul 23 '05 #94
Peter Koch Larsen wrote:
If you disregard the controversial "export" keyword, most recent compilers
are close to being 100% conforming (but might not be so "out-of-the-box").
This is a good one: All Ada templates are export since 1983 and most C++
compiler still can't do it.

Same for the dynamic arrays in C99 which Ada also had since 1983.
Do you also require parenthesis when mixing addition and multiplication? I
do not like that degree of nannying - a matter of taste, surely.


No! See http://adaic.org/standards/95lrm/html/RM-4-5.html.

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

Jul 23 '05 #95
Ioannis Vranos <iv*@remove.this.grad.com> writes:

[snip]
Certainly after the thread discussion, ADA has ascended a lot in my
interest scale (I always try to be reasonable).


I will give you some street respect for this and also for the fact
that the thread is actually informative and hasn't evolved into a
flamewar.

Regards,
- Mark Lorenzen
Jul 23 '05 #96
Ed Falis writes:
Ludovic Brenta writes:
That's what an unhandled exception results in. In avionics, where
we have no operating system and no run-time system, exceptions
cannot propagate and thus always result in program termination.
When testing the program, we prove that no exception is ever
raised.

There are certainly other strategies available. For instance, in an
"integrated modular avionics" architecture, an unhandled Ada
exception in a single partition could be forwarded to a global
health monitoring facility that may restart that partition, a set of
partitions, or the whole system - or do something else for error
recovery. This implies that exception propagation is a quite
flexible capability, and can be embedded in a system with even
greater error handling flexibility in a comfortable way.


The software I'm currently working on is the "boot", or "BIOS" of our
hardware. It allows us to upload an operating system onto the target
board. The OS is then responsible for the partitioning that you
describe. So, inside the "boot" software, we have absolutely nothing
we can use to propagate exceptions. Every exception results in some
processor registers being set and a "jump" instruction to a fixed
address. We can use the processor registers to easily find the point
where the exception was raised, but we cannot handle it.

In another project I worked on, there was only one partition, and
every exception would result in the watchdog restarting the software.

The mechanism you describe is indeed one possible solution for
software that runs on top of an operating system.

--
Ludovic Brenta.
Jul 23 '05 #97
In article <GZ*********************@news000.worldonline.dk> , "Peter Koch Larsen" <pk*****@mailme.dk> writes:

"Larry Kilgallen" <Ki*******@SpamCop.net> skrev i en meddelelse
news:CU**********@eisner.encompasserve.org...
In article <Fs*********************@news000.worldonline.dk> , "Peter Koch
Larsen" <pk*****@mailme.dk> writes:
It's kind of like driving. You can get into a lot of trouble if you do
not
follow the traffic laws (you just have to obey the physicla ones ;-), but
so
long as you do driving is a fairly safe practice.


Although I attempt to drive safely, I also rely on seat belts and air
bags.


I hope we all do. What i meant to say was that using a seat belt isn't an
excuse to drive on the wrong side of the road.


No, but despite always intending to drive on the proper side of the road,
I still wear a seat belt. There might be an unintended incident, such as
a bee stinging me, in which case I want to be as safe as possible.
Jul 23 '05 #98
"Martin Dowie" <ma**********@btopenworld.com> wrote in message
news:d0**********@titan.btinternet.com...
I think Modula-3 was the prime inspiration but never having used it I
could be wrong! :-)


One of the most fascinating computing documents ever written was the
"Rationale for the Design of the ADA programming Language" SIGPLAN Notices
6/79 (and yes, ADA was capitalized in that particular title, although if I
recall, in a later edition is was not.)

It is quite unusual to see such a complete treatment of what people were
thinking when they came up with a language. Anyway, in the introduction:

"The main source of inspiration for the Green language is the programming
language Pascal and its later derivatives."

However, throughout the document, they reference Algol-60 and Algol-68 much
more frequently than Pascal. That may make sense as Algol was seen as the
inspiration for Pascal, so many of Pascal's features appeared there first.
They also frequently make comparisons to Simula. In a quick scan, I didn't
see any reference to Modula, let alone Modula-3 which came a lot later -
1992 maybe?. Interestingly enough, Modula-2 also seems to have surfaced in
1979, and talks about safety-critical systems. (I get the impression there
never was a just plain Modula).

If you can get hold of a copy of the Rationale, it is a very intresting
read.

...
Jul 23 '05 #99
In comp.realtime xpyttl <xp***********@earthling.net> wrote:
1979, and talks about safety-critical systems. (I get the impression there
never was a just plain Modula).


There was, we used an elderly Modula compiler for real-time courses in
the late 80s. It was essentially Pascal with separate compilation, a
process abstraction (though I can't remember whether this was in the
language or achieved entirely through libraries), and proper abstract
data types. Modula-2 moved somewhat further from the Pascal roots (I
think mainly to make it a systems-programming language for the Lilith
workstation) then the paths forked. Modula-3 became a much bigger language;
Wirth got small with Oberon, which was a very compelling language (and
environment) that never really achieved critical mass.

pete
--
pe**@fenelon.com "Send lawyers, guns and money...."
Jul 23 '05 #100

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

Similar topics

20
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 -...
14
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...
3
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...
12
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...
16
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...
24
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...
0
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...
1
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...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
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,...
0
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...

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.