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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,f92fbb4a0420dd57 X-Google-Attributes: gid103376,public From: pitre@n5160d.nrl.navy.mil (Richard Pitre) Subject: Re: some questions re. Ada/GNAT from a C++/GCC user Date: 1996/03/30 Message-ID: <4jjul6$637@ra.nrl.navy.mil>#1/1 X-Deja-AN: 145055100 references: organization: Naval Research Laboratory newsgroups: comp.lang.ada Date: 1996-03-30T00:00:00+00:00 List-Id: In article bobduff@world.std.com (Robert A Duff) writes: > In article , > Scott Leschke wrote: > >My first question would be, why do you want redundant instantiations. > > Usually you don't. But you might declare a type Apple_Count, and not > know whether anybody wants to do I/O on it. Then one client does, and > instantiates Text_IO.Integer_IO on Apple_Count. And another client > independently does the same. One might like to share the code of the > two instantiations. > > But, as Bill Newman pointed out, the more important thing is when you > have Apple_Count and Orange_Count, which are logically distinct, but > happen to share the same hardware representation. That's a more > important case where you'd like shared generic code. > > Shared generic code isn't easy to implement in general, but many Ada 83 > compilers support it, at least for some kinds of generics. The problem > is that you can't count on it in portable code, so you have to do it "by > hand". That's not so awful, I suppose -- at least the ugly parts are > buried in one place. > > >You can use a block statement. This is different than C++ in the sense > >that objects declared within the block are only in existence within the > >block and are finalized at the end. > > No, I think this is exactly the same in C++ and Ada. See r.6.7 of The > C++ Programming Language, Second Edition, by Bjarne Stroustrup. That > is, if you declare an object in C++ in a local sequence of statements, > it will be finalized at the end of that sequence. > The only difference > is that Ada requires some extra syntactic baggage. > > >declare > > Obj : Pkg.SomeType; > >begin > > Pkg.Operation (Object => Obj); > > -- Other stuff > >exception > > when Pkg.Some_Exception => > > > > Do_Something; > >end; > > The exception handler makes this look reasonable, but in the usual case, > where there's no need for any exception handling, and you just want to > declare Obj, the extra 3 lines of code ("declare", "begin", "end") are > just an annoyance. I thing of "begin" and "end" are visual cues and I prefer them to eyeburner baggage like "{" and "}". richard