From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,15d588b58ebcebac X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!news.glorb.com!newsfeed.kamp.net!newsfeed.kamp.net!newsfeed.freenet.de!news.teledata-fn.de!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail Newsgroups: comp.lang.ada Subject: Re: Initializers From: Georg Bauhaus In-Reply-To: <1166580131.054327.67090@80g2000cwy.googlegroups.com> References: <1166580131.054327.67090@80g2000cwy.googlegroups.com> Content-Type: text/plain Content-Transfer-Encoding: 7bit Organization: # Message-Id: <1166627296.26616.31.camel@localhost> Mime-Version: 1.0 X-Mailer: Evolution 2.6.1 Date: Wed, 20 Dec 2006 16:08:16 +0100 NNTP-Posting-Date: 20 Dec 2006 16:07:50 CET NNTP-Posting-Host: 68c11287.newsspool3.arcor-online.net X-Trace: DXC=iNfF[I^B;`]@>[RYkFXOIPMcF=Q^Z^V3X4Fo<]lROoRQgUcjd<3m<;RKI_5]kME>>T=kbmW`a1fGWC`2T@AUZfC[>b0AI=?R?8_ X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:7959 Date: 2006-12-20T16:07:50+01:00 List-Id: 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