comp.lang.ada
 help / color / mirror / Atom feed
From: Tucker Taft <stt@averstar.com>
Subject: Re: Q:ADA/Java/C++ feature mapping question!?
Date: 2000/01/20
Date: 2000-01-20T19:13:12+00:00	[thread overview]
Message-ID: <38875E47.75A994CA@averstar.com> (raw)
In-Reply-To: 8672ec$e28$1@fleetstreet.Austria.EU.net

alex wrote:
> 
> Hi,
> my question should be easy to answer for anyone who knows C++/Java and ADA.
> Unfortunately I only know C++&Java :-(.
> 
> Question: What are the corresponding ADA keywords to the given C++/Java
> features, and which keywords do exist in ADA which have no representation in
> C++/Java, and what do they mean. I did have a look at the
> http://www.adahome.com/rm95/ Ada reference Manual, but this would be a
> longer way to go then I would like to. So could one of you who knows both
> languages help me out?
> 
> C++/Java Keywords of interest to me:
> 
> auto:      variable has local (automatic) extent

This is the default in Ada, as it is in C.  In fact, in Ada,
*all* local variables have "local" extent.  It is generally a rule
in Ada that the lifetime of an object is determined by where it
is declared, not by any keyword like "static" or "own" as in some languages.
If you want something to "live" longer, you need to move its declaration
out to a scope which lives longer (e.g. an enclosing package).

> abstract  (Java)  pure virtual

abstract.

> const:    functions values are not modifiable

"constant" for declared objects, and "in" for parameters

> explicit:    Constructors declared explicit will not be considered for
> implicit conversions

Ada has very few implicit conversions, generally only from numeric literals
to specific numeric types.  There are no implicit conversions based
on single-parameter constructors, as in C++.

> 
> extern:    Variable or function has external linkage, or linkage conversion
> of another language

Variables/subprograms declared in the "public" or "visible" part of a package
are accessible internally.  Note that because of inlines and generics,
entities declared in the private part or body of a package may still end
up with "extern" linkage, but this is a low-level issue.

The equivalent of C++'s 'extern "C" { ... }' are the pragmas
Import/Export/Convention (see the section on "interfacing pragmas" in
Annex B of the reference manual).

> 
> final    (Java) class, method cannot be derived from or overwritten

Any operation that is not a "primitive" operation of a type cannot be
overridden (nor is it inherited).  Any type that is not "tagged"
cannot be extended, though you can still "derive" from it without
extending.

> 
> friend:     function or class has access to private/protected class members

Child packages are similar to friends, in that they have additional
visibility onto the private declarations of their ancestor packages.

> 
> interface    (Java)  concept for abstract interface suitable for multiple
> inheritance

Generic signatures are about the closest thing in Ada 95.  A generic
signature is a generic package declaration with only a formal part,
and no declarations in the visible part.  They are useful in combination
with formal package parameters.

You can also use access discriminants and generic mixins to solve the
same kinds of problems solved by multiple inheritance.
> 
> mutable:    Non-static non const data members. If declared mutable it is
> legal to assign a value to this data member from a const member function

A "const" member function is one whose "controlling operand" is of
mode "in."  There is no notion of a "mutable" component of an "in"
object.  However, you can accomplish this by using a level of indirection.
The component would be accessed via an access-to-variable component.
The component itself might be allocated in the heap, or as an "aliased"
part of the enclosing record.
> 
> native  (Java) modifier used in the declaration of a method to indicate that
> the method is implemented in another programming language

pragma Import

> 
> namespace:    obvious

package (roughly -- C++ namespaces don't provide any visibility control)

> 
> package  (Java) obvious

package (though in Ada, the hierarchical package namespace is relevant
to visibility, whereas in Java "sub" packages have no different visibility
on their "enclosing" package than any other unrelated package.

> 
> private:     visibility for class member

declared in package body

> 
> protected:     visibility for class member

declared in private part of package spec, making it visible to child
packages.

> 
> public:    visibility for class member

Declared in visible part of package spec.

> 
> register:    "asks" compiler to place variable in CPU register

No particular equivalent.  The "inverse" exists, "aliased", which
disallows use of a register.

> 
> synchronized  (Java) modifier to specify thread-safe methods

protected, though it is on a per-type basis, rather than a per-operation basis.

> 
> static:    linkage for variables and functions

Declare in enclosing package (see above discussion about "auto")

> 
> template:    set of parameterized classes or functions

generic

> 
> virtual:    polymorphism for functions, for classes to disable multiple
> members while using multiple inheritance

dispatching operation of a tagged type.  This is per-type in Ada rather
than per-operation.  If a type is marked "tagged" then all of its
primitive operations are effectively "virtual."  If not marked tagged,
then none of its primitive operations are virtual.   Non-primitive
operations are never "virtual."

> 
> transient  (Java) modifier used in the declaration of variables

No particular equivalent.  Would probably be done with a pragma in Ada.

> 
> volatile:    type qualifier; object can be modified in the program by
> something other than statements, such as the operating system, the hardware,
> or a concurrently executing thread

pragma Volatile  (also see pragma Atomic, which is related).

> 
> Thank you very much in advance for any help!
> 
> cu,
> alex

-- 
-Tucker Taft   stt@averstar.com   http://www.averstar.com/~stt/
Technical Director, Distributed IT Solutions  (www.averstar.com/tools)
AverStar (formerly Intermetrics, Inc.)   Burlington, MA  USA




  parent reply	other threads:[~2000-01-20  0:00 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-01-20  0:00 Q:ADA/Java/C++ feature mapping question!? alex
2000-01-20  0:00 ` Jim Rogers
2000-01-20  0:00 ` Vladimir Olensky
2000-01-20  0:00 ` carlislemc
2000-01-20  0:00   ` alex
2000-01-20  0:00 ` Tucker Taft [this message]
2000-01-20  0:00   ` Ted Dennison
2000-01-20  0:00   ` Brian Rogoff
2000-01-21  0:00 ` alex
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox