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: 109fba,f92fbb4a0420dd57 X-Google-Attributes: gid109fba,public X-Google-Thread: 103376,f92fbb4a0420dd57 X-Google-Attributes: gid103376,public From: leschkes@ferret.cig.mot.com (Scott Leschke) Subject: Re: some questions re. Ada/GNAT from a C++/GCC user Date: 1996/03/28 Message-ID: #1/1 X-Deja-AN: 144751048 references: organization: Motorola Cellular Infrastructure Group newsgroups: comp.lang.ada,comp.lang.c++ Date: 1996-03-28T00:00:00+00:00 List-Id: wnewman@netcom.com (Bill Newman) writes: >When I make two different instantiations of a generic package with the >same arguments, I understand the compiler treats them formally as two >different packages, which is OK with me. However, I'd appreciate >knowing the compiler wouldn't actually output two redundant copies of >the corresponding (identical?) machine code, but instead share the >code. I saw somewhere that the compiler is given considerable freedom >to share one instantiation between several arguments if it thinks it's >appropriate, which is also OK with me. However, I haven't seen any >guarantee that the compiler won't output redundant copies for >instantiations with identical arguments. Is there such a guarantee? My first question would be, why do you want redundant instantiations. Note that Ada separates instantiation of a generic from use of the resulting package/subunit. The general rule of thumb to avoid code-bloat due to duplicate instantiations is to do the instantiation at the library level and 'with' the resulting package/subunit. >Why doesn't Ada 95 allow declarations to be interspersed with ordinary >statements as C++ does? (Or does it? _Ada as a Second Language_ is a >big book!) It seems to me that the C++ approach is a small but >definite win. Does it interact very badly somehow with all those >guarantees on elaboration order? 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. A block can also have its own exception handlers. The syntactic form is (from page 500 of the LRM): block statement ::= [block_statement_identifier:] [declare declarative_part] begin handled_sequence_of_statements end [block_identifier]; Note that the block identifier and declaration section are optional. For example: declare Obj : Pkg.SomeType; begin Pkg.Operation (Object => Obj); -- Other stuff exception when Pkg.Some_Exception => Do_Something; end; -- Scott Leschke.........................email: leschkes@cig.mot.com Motorola, Inc............................ph: 847-632-2786 1501 W Shure Drive......................fax: 847-632-3145 Arlington Heights, IL 60004......mailstop: 1301