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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no 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!postnews.google.com!48g2000cwx.googlegroups.com!not-for-mail From: "markww" Newsgroups: comp.lang.ada Subject: Re: Initializers Date: 20 Dec 2006 12:59:49 -0800 Organization: http://groups.google.com Message-ID: <1166648388.945552.17000@48g2000cwx.googlegroups.com> References: <1166580131.054327.67090@80g2000cwy.googlegroups.com> <1166627296.26616.31.camel@localhost> NNTP-Posting-Host: 67.154.89.221 Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" X-Trace: posting.google.com 1166648395 9763 127.0.0.1 (20 Dec 2006 20:59:55 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 20 Dec 2006 20:59:55 +0000 (UTC) In-Reply-To: <1166627296.26616.31.camel@localhost> User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727),gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: 48g2000cwx.googlegroups.com; posting-host=67.154.89.221; posting-account=cNKOMg0AAADT2ug8oGSYYXo8bsDvrHzw Xref: g2news2.google.com comp.lang.ada:7960 Date: 2006-12-20T12:59:49-08:00 List-Id: Georg Bauhaus wrote: > 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 Ok thanks for your replies. I also found this on 'elaboration': http://www.adapower.com/rm95/RM-7-6.html where do you guys find examples of how to use these packages? Thanks, Mark