From: Georg Bauhaus <bauhaus@arcor.de>
Subject: Re: Initializers
Date: Wed, 20 Dec 2006 16:08:16 +0100
Date: 2006-12-20T16:07:50+01:00 [thread overview]
Message-ID: <1166627296.26616.31.camel@localhost> (raw)
In-Reply-To: <1166580131.054327.67090@80g2000cwy.googlegroups.com>
On Tue, 2006-12-19 at 18:02 -0800, markww wrote:
> Hi everyone,
>
> I'm trying to compare C++ to Ada. I'm looking specifically at Ada's
> lack of 'initializers'. I am guessing that this means there is no
> 'constructor' to Ada packages maybe?
Others have given examples of initialization of record components
and of package initialization blocks. (Two different things.)
Another 2c:
There are also construction subprograms and nested Factory packages
that are commonly used for initializing objects. Some of this is
explained in the Ada wikibook, and in many Ada text books.
In addition, consider:
- types whose objects must not be initialised, not even default
initialized. A reason might be that their bits are mapped
to hardware. Initialization would mean sending signals to the
hardware. You don't want some signals sent only because the
language uses some default initialization. So in Ada, you can
turn initialization off, entirely.
- limited types. For every object of a limited record you can
obtain its access within the record definition. This allows
one or more construction functions invoked automatically
when an object is created but not initialized "by hand":
package P is
type L is limited private;
package Factory is
function make(item: access L) return Natural;
end Factory;
private
type L is limited record
hook: Natural := Factory.make(L'access);
stuff: Integer;
end record;
end P;
Factory.make has access to all the components of its Item
parameter, including Stuff. It is invoked automatically
for an object of type L that isn't explicitly initialized.
- discriminated types. These will force partial initialization
because the discriminant needs to have a value to make the
object be of some specific type, and have a known size etc.
There are some tricks here.
- nested scope. This is useful if you compare initialization in
C++ and Ada because nesting is built into Ada and can be used
here. Support for nested scopes (dynamic + static) is limited
in C++ by comparison I think. There are cases where
you would pass parameters to a C++ constructor, where in Ada
you needn't pass them because they are in (local) scope.
-- Georg
next prev parent reply other threads:[~2006-12-20 15:08 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-12-20 2:02 Initializers markww
2006-12-20 4:52 ` Initializers Larry Kilgallen
2006-12-20 7:59 ` Initializers Jean-Pierre Rosen
2006-12-20 6:57 ` Initializers Martin Krischik
2006-12-20 10:35 ` Initializers Dmitry A. Kazakov
2006-12-20 15:08 ` Georg Bauhaus [this message]
2006-12-20 20:59 ` Initializers markww
2006-12-21 5:14 ` AW: Initializers Grein, Christoph (Fa. ESG)
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox